bind: functionBind,
call: functionCall,
} = functionPrototype;
- const callBind = Reflect.apply(functionBind, functionCall, [
- functionBind,
- ]);
+ const { apply: reflectApply } = Reflect;
const {
create: objectCreate,
defineProperty: defineOwnProperty,
getPrototypeOf: getPrototype,
setPrototypeOf: setPrototype,
} = Object;
+ const callBind = reflectApply(functionBind, functionCall, [
+ functionBind,
+ ]);
const { [ITERATOR]: arrayIterator } = Array.prototype;
const {
next: arrayIteratorNext,
} else {
// Properties were provided; apply them.
const { length, name, prototype } = override;
- if (
- !isConstructor($) || !hasOwnProperty($, "prototype") ||
- prototype === undefined
- ) {
- // The provided function is not a constructor, has no
- // `.prototype`, or no prototype value was provided.
+ if (!hasOwnProperty($, "prototype") || prototype === undefined) {
+ // The provided function has no `.prototype` or no prototype
+ // value was provided.
//
// Do not modify the prototype property of the provided
// function.
createArrowFunction: ($, propertyOverride = undefined) =>
applyProperties(
applyBaseFunction(
- (...$s) =>
- $(...objectCreate(
- argumentIterablePrototype,
- { args: { value: $s } },
- )),
+ (...$s) => reflectApply($, undefined, $s),
$,
),
propertyOverride,
{ args: { value: $s } },
)[ITERATOR]();
const { value: thisValue } = iterator.next();
- return call($, thisValue, [...iterator]);
+ return reflectApply($, thisValue, [...iterator]);
},
$,
1,
),
propertyOverride,
),
- createIllegalConstructor: ($, propertyOverride = undefined) => {
- const constructor = applyProperties(
- applyBaseFunction(
- function () {
- throw new TypeError("Illegal constructor");
- },
- $,
+ createIllegalConstructor: ($, propertyOverride = undefined) =>
+ defineOwnProperty(
+ applyProperties(
+ applyBaseFunction(
+ function () {
+ throw new TypeError("Illegal constructor");
+ },
+ $,
+ ),
+ propertyOverride,
),
- propertyOverride,
- );
- return defineOwnProperty(constructor, "prototype", {
- writable: false,
- });
- },
- };
-})();
-
-export const {
- /**
- * Calls the provided function with the provided this value and
- * arguments list.
- *
- * ☡ This is effectively an alias for `Reflect.apply`—the arguments
- * must be passed as an arraylike.
- */
- call,
-
- /**
- * Constructs the provided function with the provided arguments list
- * and new target.
- *
- * ☡ This is effectively an alias for `Reflect.construct`—the
- * arguments must be passed as an arraylike.
- */
- construct,
-
- /** Returns whether the provided value is a constructor. */
- isConstructor,
-} = (() => {
- const { apply, construct } = Reflect;
- return {
- call: (target, thisArgument, argumentsList) =>
- apply(target, thisArgument, argumentsList),
- construct: (target, argumentsList, ...args) =>
- args.length > 0
- ? construct(target, argumentsList, args[0])
- : construct(target, argumentsList),
- isConstructor: ($) =>
- completesNormally(() =>
- // 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 () {}, [], $)
+ "prototype",
+ { writable: false },
),
};
})();
+/**
+ * Calls the provided function with the provided this value and
+ * arguments list.
+ *
+ * ☡ This is effectively an alias for `Reflect.apply`—the arguments
+ * must be passed as an arraylike.
+ */
+export const call = createArrowFunction(Reflect.apply, {
+ name: "call",
+});
+
/**
* Returns whether calling the provided function with no `this` value
* or arguments completes normally; that is, does not throw an error.
}
};
+/**
+ * Constructs the provided function with the provided arguments list
+ * and new target.
+ *
+ * ☡ This is effectively an alias for `Reflect.construct`—the
+ * arguments must be passed as an arraylike.
+ */
+export const construct = createArrowFunction(Reflect.construct);
+
/**
* Returns the provided value.
*
/** Returns whether the provided value is callable. */
export const isCallable = ($) => typeof $ === "function";
+/** Returns whether the provided value is a constructor. */
+export const isConstructor = ($) =>
+ completesNormally(() =>
+ // 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 () {}, [], $)
+ );
+
/**
* Returns whether the provided object inherits from the prototype of
* the provided function.