call
Function.prototype.myCall = function(context) {
if (context === null || context === undefined) {
this(...Array.from(arguments).slice(1));
} else {
context.constructor.prototype.fun = this;
context.fun(...Array.from(arguments).slice(1));
delete context.constructor.prototype.fun;
}
}
apply
Function.prototype.myApply = function(context) {
if (context === null || context === undefined) {
this(...arguments[1] || []);
} else {
context.constructor.prototype.fun = this;
context.fun(...arguments[1] || []);
delete context.constructor.prototype.fun;
}
}
bind
Function.prototype.myBind = function(context) {
return () => this.myCall(context, ...arguments);
}
如果有问题,还请各位帮我指出其中的不足之处