Function.prototype.mycall = function(myobj = window, ...args) {
if(typeof myobj === "function") {
throw new TypeError("error");
}
const fn = Symbol("fn");
myobj[fn] = this;
const result = myobj[fn](...args);
delete myobj[fn];
return result;
}
Function.prototype.myapply = function(myobj = window, args = []) {
if(typeof myobj === "function") {
throw new TypeError("error");
}
const fn = Symbol("fn");
myobj[fn] = this;
const result = myobj[fn](...args);
delete myobj[fn];
return result;
}
Function.prototype.mybind = function(myobj, ...args) {
if(typeof myobj === "function") {
throw new TypeError("error");
}
let self = this;
let bound = function() {
let _this = this instanceof self ? this : myobj;
self.apply(_this, [...args, ...arguments]);
};
return bound;
}