-
Notifications
You must be signed in to change notification settings - Fork 2
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
functions extracted from objects unbound by default #13
Comments
@tvcutsem: But how would you unbind a function? Once bound, that function's context becomes useless. |
I wouldn't argue to ever unbind a bound function. Instead, if binding-on-extraction using the dot-operator would have been the default, I would imagine one could still get at the unbound function using reflection, e.g. |
Finally maybe the default behavior is the one that indicates fat arrow :
Of course, one could have expected the contrary (ie |this| is obj for both) I did not deeply think about it but doing this project https://github.com/Ayms/node-Tor where the use of "var self=this" is replaced by "bind" (for future replacement by =>) at a certain point of time it came to me the question : "why don't we have an unbind ?", but apparently you are saying that's it's not arguable |
A common mistake in JS is to extract a method from an object (as a first-class function value), then call the function without providing a binding for
this
. Example:I think the ability to be able to extract methods as unbound functions is useful and powerful (it allows for easy sharing of methods among different objects), but it seems this mistake is so common that extracting methods as bound functions could have been the default.
The text was updated successfully, but these errors were encountered: