Array.forEach() et al with additional parameters

David Bruant bruant.d at gmail.com
Mon Dec 22 02:37:04 PST 2014


Le 20/12/2014 13:47, Gary Guo a écrit :
> bindParameter function is not very hard to implement:
> ```
> Function.prototype.bindParameter=function(idx, val){
>     var func=this;
>     return function(){
>         var arg=Array.prototype.slice.call(arguments);
>         arg[idx]=val;
>         func.apply(this, arg);
>     }
> }
> ```
It's even easier if you use bind ;-)

Function.prototype.bindParameter = function(...args){
     return this.bind(undefined, ...args)
}

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141222/2607cac4/attachment-0001.html>


More information about the es-discuss mailing list