call.js
var name = 'zs';
let obj1 = {
name: 'ls'
};
function fn(a,b) {
console.log(this.name + a+b);
};
Function.prototype.myCall = function (obj, ...args) {
obj.fun = this;
console.log(obj);
obj.fun(...args);
delete obj.fun;
console.log(obj)
}
fn.myCall(obj1,'a','b');
apply.js
var name = 'zs';
let obj1 = {
name: 'ls'
};
a=[1,23,4]
function fn(a, b) {
console.log(this.name + a + b);
};
Function.prototype.myaplly = function (obj, array = []) {
obj.fun = this;
obj.fun(...array);
delete obj.fun;
}
fn.myaplly(obj1,['1','2'])
bind.js
Function.prototype.mybind = function (obj, ...args) {
return (...args2)=>{
obj.fn=this
obj.fn(...args.concat(args2))
delete obj.fn
}
}