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
new
operator misbehavior
#619
Comments
Wow, that's fascinating. So you're saying that every major JS implementation evaluates
as
rather than what I would expect:
I'm very surprised by this. |
FM moment:
I bet this has something to do with Coffee adding |
After messing around with it, I don't believe that the initial premise of this ticket is correct.
... works correctly in both JavaScript and CoffeeScript, not the way that you assert it does. Stan's test case got screwy because he wasn't returning
Which is all well and good. Closing the ticket as |
Not quite.
|
Not quite. Your test case doesn't produce the same result in JS.
Note the 3rd being blank because |
Sure, that's fine -- CoffeeScript fixes this broken JS behavior by compiling the 3rd line like so:
Note the trailing parentheses. This makes the output correct. |
This exhibits a classic JS pitfall--doesn't [[Construct]] Try appending:
to your test case. |
ugh, how is that possible? ... Fuck me, indeed. satyr got any documentation links for this behavior? |
http://ecma262-5.com/ELS5_Section_11.htm#Section_11.2 |
I've been toying with this a bit, and it's really as nasty as satyr describes. I need some help with this piece of it. Say you want to construct a new object from a require'd property, and you want to pass arguments to the constructor. Is this possible to write in JavaScript?
With any combination of parentheses? |
|
The patch is now on master, to fix the behavior to do the expected thing ... not the JavaScript thing: http://github.com/jashkenas/coffee-script/commit/e7834de92974f997e692dd1c11f735a71078666f Thanks, satyr, for bringing up this issue. It's a nasty JS gotcha that I hadn't suffered before, and was completely unaware of. It's wonderful that we're in a position to be able to do something about it. Edit: Nevermind -- the cure was worse than the disease. Reverted. |
wontfix...? |
This is still an issue. I'm not sure why it's closed.
Fixed in CoffeeScriptRedux edit: Also, check this out:
Eek. Not good. |
How? Seems working to me. The AST looking incorrect is less important.
→ #1189 |
There is a common misconception regarding
new
in JS, producing code like this:The intent here is to create a Bar instance, but fails because the RHS evaluates as
(new require("foo")).Bar
.CoffeeScript doesn't correct this situation, but makes it worse:
I can think of three compile options:
The text was updated successfully, but these errors were encountered: