New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Function.bind #318
Comments
Simple workaround (without args):
|
Alternative, with args support: Function.prototype.bind = function(thisArg) {
var f = this;
var bArgs = [].slice.call(arguments, 1);
return function() {
return f.apply(thisArg, [].concat.apply(bArgs, arguments));
};
};
function f(a, b, c) {
console.log(this, a, b, c);
}
var bound = f.bind({}, 1, 2);
bound(3);
// {} 1 2 3 |
This could be really good for outputting data quickly. For example:
Also for passing data into code created with inline assembler... So it definitely needs to work for built-in functions too - and efficiently. |
As long as it's defined on Function.prototype then it will work on all built-ins, right? |
Yes - but it's more how we do the implementation if we want it to be faster than if we'd just used the JS replacement above. jwsCallFunction does 2 completely different things depending on whether the function is native or not - not to mention whether it is parsing or not :( |
Indeed, bind in plain js is slow |
Seems to be required by some people...
http://es5.github.io/#x15.3.4.5
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
The text was updated successfully, but these errors were encountered: