X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/29307967cb084aceaa9265fe22af4348c9e4376a..83f6aae0d1b8181dc2b0c6ccdba9f2fe2fdba3e6:/function.js?ds=inline diff --git a/function.js b/function.js index 46cab86..5f397a9 100644 --- a/function.js +++ b/function.js @@ -1,19 +1,21 @@ // ♓🌟 Piscēs ∷ function.js // ==================================================================== // -// Copyright © 2022 Lady [@ Lady’s Computer]. +// Copyright © 2022‐2023 Lady [@ Lady’s Computer]. // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at . +import { ITERATOR } from "./value.js"; + 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, @@ -22,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, } = (() => { @@ -40,13 +42,12 @@ export const { defineProperty: defineOwnProperty, getPrototypeOf: getPrototype, } = Object; - const { iterator: iteratorSymbol } = Symbol; - const { [iteratorSymbol]: arrayIterator } = Array.prototype; + const { [ITERATOR]: arrayIterator } = Array.prototype; const { next: arrayIteratorNext, - } = getPrototype([][iteratorSymbol]()); + } = getPrototype([][ITERATOR]()); const argumentIterablePrototype = { - [iteratorSymbol]() { + [ITERATOR]() { return { next: callBind( arrayIteratorNext, @@ -74,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. @@ -111,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; } };