草庐IT

bindRight

全部标签

Javascript:绑定(bind)到函数的右侧?

如何绑定(bind)到函数的右边?示例:varsquare=Math.pow.bindRight(2);console.log(square(3));//desiredoutput:9 最佳答案 Function.prototype.bindRight=function(){varself=this,args=[].slice.call(arguments);returnfunction(){returnself.apply(this,[].slice.call(arguments).concat(args));};};varsqu