1 // ♓🌟 Piscēs ∷ function.js
2 // ====================================================================
4 // Copyright © 2022 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
12 * Creates a bound function from the provided function using the
13 * provided this value and arguments list.
15 * ☡ As with call and construct, the arguments must be passed as an
21 * Returns a new function which calls the provided function with its
22 * first argument as the `this` value and the remaining arguments
25 * ※ This is effectively an alias for Function.prototype.call.bind.
29 // ☡ Because these functions are used to initialize module constants,
30 // they can’t depend on imports from elsewhere.
34 } = Function
.prototype;
35 const callBind
= Reflect
.apply(functionBind
, functionCall
, [
40 defineProperty
: defineOwnProperty
,
41 getPrototypeOf
: getPrototype
,
43 const { iterator
: iteratorSymbol
} = Symbol
;
44 const { [iteratorSymbol
]: arrayIterator
} = Array
.prototype;
46 next
: arrayIteratorNext
,
47 } = getPrototype([][iteratorSymbol
]());
48 const argumentIterablePrototype
= {
53 call(arrayIterator
, this.args
, []),
59 bind
: ($, boundThis
, boundArgs
) =>
64 argumentIterablePrototype
,
65 { args
: { value
: boundArgs
} },
70 callBind(functionCall
, $),
72 { value
: $.length
+ 1 },
78 * Calls the provided function with the provided this value and
81 * ☡ This is an alias for Reflect.apply—the arguments must be passed
84 export const call
= Reflect
.apply
;
87 * Constructs the provided function with the provided arguments list
90 * ☡ This is an alias for Reflect.construct—the arguments must be
93 export const construct
= Reflect
.construct
;
96 * Returns the provided value.
98 * ※ This function can be called as a constructor. When used in an
99 * `extends` clause and called via `super`, it will set the value of
100 * `this` to the provided value, enabling it to be extended with
101 * private class features.
103 export const identity = function ($) {
107 /** Returns whether the provided value is callable. */
108 export const isCallable
= ($) => typeof $ === "function";
110 /** Returns whether the provided value is a constructor. */
111 export const isConstructor
= ($) => {
112 // The provided value is an object.
118 ); // will throw if $ is not a constructor
126 * Returns whether the provided object inherits from the prototype of
127 * the provided function.
129 export const ordinaryHasInstance
= makeCallable(
130 Function
.prototype[Symbol
.hasInstance
],