Loading problem…
Implement your own version of Function.prototype.apply.
The apply method calls a function with a given this value and arguments provided as an array (or array-like object).
Your implementation must:
thisArg parameter to be used as the function's thisargsArray parameter containing argumentsthisArgYou must correctly handle:
null or undefined as thisArg (default to globalThis)thisArg values (must be boxed to objects)null/undefined argsArray (treat as empty list)argsArray objects (e.g. arguments, {0: 'a', length: 1})argsArray (must throw TypeError)this)Some hidden tests express “expected to throw” using an output marker like:
throwError("TypeError")
throwError("Error") // any Error subtypefunction greet(greeting, punctuation) {
return `${greeting}, ${this.name}${punctuation}`;
}
const person = { name: "Alice" };
greet.myApply(person, ["Hello", "!"]);
// "Hello, Alice!"