Implement a function myApply(fn, thisArg, args) that calls the given function fn with a specified this value and arguments provided as an array.
Arguments
fn: Function to be calledthisArg: The value of this inside the functionargs: An array of arguments to pass to the functionExample
function greet(greeting, name) { return greeting + ', ' + name + '!'; } myApply(greet, { }, ['Hello', 'Alice']); // 'Hello, Alice!' const obj = { x: 10 }; function add(a, b) { return this.x + a + b; } myApply(add, obj, [5, 5]); // 20
JavaScript Function
No test results yet
Click "Run" to execute tests