Function.prototype.bind1 = function () {
// 将参数解析数组
const args = Array.prototype.slice.call(arguments);
// 获取 this (取出数组第一项,数组剩余的就是传递的参数)
const t = args.shift();
const self = this; // 当前函数
// 返回一个函数
return function () {
// 执行原函数,并返回结果
return self.apply(t, args);
}
}
Function.prototype.apply1 = function (context, args) {
if(context == null) {
context = window;
}
const self = this;
const res = self(...args);
return res;
}
Function.prototype.call1 = function() {
const args = [...arguments];
const t = args.shift();
const self = this;
const res = self(args);
return res;
}
console