X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/da52ccecff0e48d48ea235b4d0def93b149eb0c1..83f6aae0d1b8181dc2b0c6ccdba9f2fe2fdba3e6:/function.js?ds=sidebyside diff --git a/function.js b/function.js index 72b3b0d..5f397a9 100644 --- a/function.js +++ b/function.js @@ -14,8 +14,8 @@ export const { * Creates a bound function from the provided function using the * provided this value and arguments list. * - * ☡ As with call and construct, the arguments must be passed as an - * array. + * ☡ As with `call` and `construct`, the arguments must be passed as + * an array. */ bind, @@ -24,7 +24,7 @@ export const { * first argument as the `this` value and the remaining arguments * passed through. * - * ※ This is effectively an alias for Function.prototype.call.bind. + * ※ This is effectively an alias for `Function::call.bind`. */ makeCallable, } = (() => { @@ -75,23 +75,25 @@ export const { }; })(); -/** - * Calls the provided function with the provided this value and - * arguments list. - * - * ☡ This is an alias for Reflect.apply—the arguments must be passed - * as an array. - */ -export const call = Reflect.apply; +export const { + /** + * Calls the provided function with the provided this value and + * arguments list. + * + * ☡ This is an alias for `Reflect.apply`—the arguments must be + * passed as an arraylike. + */ + apply: call, -/** - * Constructs the provided function with the provided arguments list - * and new target. - * - * ☡ This is an alias for Reflect.construct—the arguments must be - * passed as an array. - */ -export const construct = Reflect.construct; + /** + * Constructs the provided function with the provided arguments list + * and new target. + * + * ☡ This is an alias for `Reflect.construct`—the arguments must be + * passed as an arraylike. + */ + construct, +} = Reflect; /** * Returns the provided value. @@ -112,13 +114,17 @@ export const isCallable = ($) => typeof $ === "function"; export const isConstructor = ($) => { // The provided value is an object. try { + // Try constructing a new object with the provided value as its + // `new.target`. This will throw if the provided value is not a + // constructor. construct( function () {}, [], $, - ); // will throw if $ is not a constructor + ); return true; } catch { + // The provided value was not a constructor. return false; } };