Function.prototype.myCall = function (target,...args){
target = target || globalThis;
const prop = Symbol();
target[prop] = this;
var result = target[prop](...args);
delete target[prop];
return result;
}
function person (name,age){
console.log("I am " + this.name);
console.log(age);
}
var david = {
name:'david'
}
person.myCall(david,'',28);
Function.prototype.myApply = function (target,args){
target = target || globalThis;
const prop = Symbol();
target[prop] = this;
var result = target[prop](...args);
delete target[prop];
return result;
}
function person (name,age){
console.log("I am " + this.name);
console.log(age);
}
var david = {
name:'david'
}
person.myApply(david,['',28]);
Function.prototype.myBind = function (target){
target = target || globalThis;
var self = this;
return function(...args){
self.apply(target,args);
}
}
function person (age){
console.log("I am " + this.name);
console.log(age);
}
var david = {
name:'david'
}
var Asian = person.myBind(david);
Asian(18);