1 decade ago by amadeus
I found the implementation of Function.bind included in ImpactJS doesn't actually work with supplied arguments.
Current Implementation:
The problem with this implementation is that 'arguments', being a reserved keyword, doesn't actually transfer through on the closure since the returned method when executed uses it's own local version of arguments, which is obviously empty. Furthermore, even if arguments would get passed along, the first arg would be the scope and thus break the returned series of arguments, since scope would be first.
There are a couple possible fixes, one would be actually creating a local variable that's equal to a slice of arguments starting at index 1, the other, and probably better fix would be to use the MDN solution since it's considered ECMA script compliant:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
Current Implementation:
Function.prototype.bind = Function.prototype.bind || function(bind) { var self = this; return function(){ var args = Array.prototype.slice.call(arguments); return self.apply(bind || null, args); }; };
The problem with this implementation is that 'arguments', being a reserved keyword, doesn't actually transfer through on the closure since the returned method when executed uses it's own local version of arguments, which is obviously empty. Furthermore, even if arguments would get passed along, the first arg would be the scope and thus break the returned series of arguments, since scope would be first.
There are a couple possible fixes, one would be actually creating a local variable that's equal to a slice of arguments starting at index 1, the other, and probably better fix would be to use the MDN solution since it's considered ECMA script compliant:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind