// ♓🌟 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 <https://mozilla.org/MPL/2.0/>.
+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,
* 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,
} = (() => {
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,
};
})();
-/**
- * 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.
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;
}
};