-
Notifications
You must be signed in to change notification settings - Fork 2k
fixes #1966: external constructors should produce their return value #1970
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
Conversation
Yikes, |
That's not undesirable behaviour. It's consistent. The class syntax is just a sugar for adding prototype properties in an IIFE. Which constructor we're talking about is specified with the special
|
If this patch is accepted both returning the new instance, and returning something else (which is useful) would be possible, since we can still return |
Thanks Michael. Your solution is much more elegant. Wasn't aware of the I actually saw this pull request before but found the test case hard to decipher so I thought I'd take a stab at it, if only to clarify why this behavior is desirable. With this modification, adding an identity map to Backbone is just a few lines of code when all other solutions I've seen are forced to duplicate |
@islandr: glad it will help you. |
Identity map is the exakt use case I've been toying around with this as well, thank you for merging, will have to play with it and see how it works now! |
@jnicklas: It hasn't been merged yet. I'm waiting for approval from @jashkenas and hopefully @TrevorBurnham will come around. |
Yep -- thanks for the pull req. |
fixes #1966: external constructors should produce their return value
Awesome. Thanks guys! |
I'm not 100% on this, but it seems better than the alternative, which would be to treat the return value of already-defined functions differently when pointed to as an external constructor.
edit: I'm pretty comfortable with it now. See my comment below.