软绑定和箭头函数的this
软绑定
//软绑定代码
if( !Function.prototype.softBind) {
Function.prototype.softBind = function(obj){
var fn = this;
//捕获所有curried 参数
var curried = [].slice.call(arguments,1);
var bound = function() {
return fn.apply(
(!this || this === (window || global))?
obj : this,
curried.concat.apply( curried,arguments);
);
};
bound.prototype = Object.creat( fn.prototype );
return bound;
}
}
箭头函数this词法
Last updated