Implement a function myBind(thisArg, ...args) that works like Function.prototype.bind.
It should return a new function with the this keyword set to the provided thisArg and optionally prepended arguments.
Arguments
thisArg: The value to be set as this in the function.args: Arguments to prepend to the function call.Example
function greet(greeting, name) { return greeting + ', ' + name + '!'; } const sayHelloToAlice = greet.myBind({}, 'Hello', 'Alice'); sayHelloToAlice(); // 'Hello, Alice!' const obj = { x: 10 }; function add(a, b) { return this.x + a + b; } const boundAdd = add.myBind(obj, 5); boundAdd(5); // 20
JavaScript Function
No test results yet
Click "Run" to execute tests