mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
823 B
823 B
constant
::: info
This function is only available in es-toolkit/compat
for compatibility reasons. It either has alternative native JavaScript APIs or isn’t fully optimized yet.
When imported from es-toolkit/compat
, it behaves exactly like lodash and provides the same functionalities, as detailed here.
:::
Creates a new function that always returns value
.
Signature
function constant(): () => undefined;
function constant<T>(value: T): () => T;
Parameters
value
(T
): The value to return from the new function.
Returns
(() => T | undefined
): The new constant function.
Examples
const object = { a: 1 };
const returnsObject = constant(object);
returnsObject(); // => { a: 1 }
returnsObject() === object; // => true