let objT = { test: '123' };
Function.prototype['myCall'] = function (target, ...args) {
//this为fncCall
target.fn = this;
target.fn(...args);
delete target.fn;
};
function fncCall(test) {
console.log(test);
console.log(this.test);
}
fncCall.myCall(objT, 789);
js模拟实现call(很简单的方法)
最新推荐文章于 2022-09-26 10:10:23 发布
本文介绍了一种在JavaScript中自定义Function.prototype.myCall的方法,实现了类似原生call的功能,通过临时将函数绑定到目标对象上并调用,最后清除绑定。
2065





