Write a function named customBind
that will be used to extend the Function prototype.
It will receive 2 parameters:
newThis
params
The function should return a new function - let's call it bindedFn
- that doesn't accept any parameters.
When calling it we should actually call the initial function but using newThis
as the this
context and the items inside params
Array as arguments.
Function.prototype.customBind = customBind;
function addToThis(nr1, nr2) {
return this + nr1 + nr2;
}
const bindedFn = addToThis.customBind(5, [10, 15]);
console.log(bindedFn()); // 30