/** * @description: bind()方法创建一个新的函数,在调用时设置this关键字为提供的值。 * 并在调用新函数时,将给定列表参数作为原函数的参数序列的前若干项 */ Function.prototype.bindTest=function (context){ if(typeofthis !=="function"){ thrownewError("Function.prototype.bind-what is trying to be bound is not callable"); } var self=this; var args=Array.prototype.slice.call(arguments,1); var fNOP=function (){}; var fBound=function (){ var bindArgs=Array.prototype.slice.call(arguments); return self.apply(thisinstanceof fBound?this:context,args.concat(bindArgs)); } fNOP.prototype=this.prototype; fBound.prototype=new fNOP(); return fBound; }