The polyfill of bind which I find online is something like -
Function.prototype.bind = function(obj, ...args) {
const self = this;
return function(...args2) {
return self.apply(obj, [...args, ...args2]);
};
}
where we use call/apply to call the function.
My question is why not simplify it to be
Function.prototype.myBind = function (obj, ...args) {
obj.func = this;
return function (...params) {
return obj.func(...args, ...params)
}
};
because internally both call and apply assign the function to the object and then execute it.