bind Function.prototype.bind = function (context) { if (typeof this !== "function") { throw new Error("Function.prototype.bind - is not a function"); } var self = this;// 保存原函数 var args = Array.prototype.slice.call(arguments, 1);// 获取bind后函数传入的参数 var fNOP = function () {}; var bound = function () { self.apply(this instanceof fNOP ? this : context, args.concat(Array.prototype.slice.call(arguments))); } fNOP.prototype = this.prototype;// 把this原型上的东西挂载到func原型上面 bound.prototype = new fNOP();// 为了避免func影响到this,通过new 操作符进行复制原型上面的东西 return bound; } call Function.prototype.call = function(context = window) { context.fn = this; let args = [...arguments].slice(1) let result = context.fn(...args); delete context.fn; return result; } apply Function.prototype.apply=function(context = window){ context.fn=this; let result; if(arguments[1]) { result = context.fn(...arguments[1]) } else { result = context.fn() } delete context.fn; return result; }