Function.prototype.call1 = function (context, ...args) {
context = context ? Object(context) : window;
args = args || [];
context.fn = this;
const result = context.fn(...args);
delete context.fn;
return result;
};
Function.prototype.apply1 = function (context, args) {
context = context ? Object(context) : window;
args = args || [];
context.fn = this;
const result = context.fn(...args);
delete context.fn;
return result;
};
Function.prototype.bind1 = function (context, ...args) {
context = context ? Object(context) : window;
args = args || [];
context.fn = this;
return (...argArr) => {
const result = context.fn(...args, ...argArr);
delete context.fn;
return result;
};
};
JS重写call/apply/bind
最新推荐文章于 2024-07-11 20:55:36 发布