Function .prototype.bindSelf= function(context){
var that = this;
returnfunction(){
that.apply(context)
}
}
复制代码
Two
Function . prototype . bind2 = function(context){
var that = this;
//获取参数
var args = Array.prototype.slice.call(arguments,1);
returnfunction(){
var bindArgs = Array.prototype.slice.call(arguments)
that .apply(context,args.concat(bindArgs))
}
}
复制代码
Three
Function.prototype.bind = function(context){
var that = this;
var args = Array.prototype.slice.call(arguments,1);
var Fun = function(){}
var Func = function(){
var bindArgs = Array.prototype.slice.call(arguments);
that.apply(this instanceof that ? this : context,bindArgs)
}
Fun.prototype = this.prototype;
Func.prototype = new Fun();
return Func;
}
复制代码