|
|
|
|
|
by jongar_xyz
3478 days ago
|
|
> #2: Goal: To be able to understand this function:
>
> // The .bind method from Prototype.js
> Function.prototype.bind = function(){
> var fn = this, args = > Array.prototype.slice.call(arguments), object = args.shift();
> return function(){
> return fn.apply(object,
> args.concat(Array.prototype.slice.call(arguments)));
> };
> } I do not want to understand this absurdness. I want a comment that tells me what it does so I can rewrite it in a sane way. |
|
Is that function that insane? I can understand it at a glance, and performance is high (it matters here). AS a JS programmer, just knowing that it is an implementation of bind() should be enough of a hint that it uses its first argument as context, the rest as a curry and the arguments of the newly generated function as additional arguments.