You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposal
Move the generated function declaration to the first line of the generated class.
Issue
Coffeescript currently outputs the __extends call prior to the function declaration of generated classes while order of execution is actually the opposite.
Rationale
While this currently causes no errors due to the happy coincidence that function declarations are always executed first, I believe implementing the proposed change avoids confusion for those trying to understand the generated code.
<Adrian_> I've got a couple suggested changes to coffeescript compiler behavior that I would like to get feedback on before I submit...
<Adrian_> Class Extends behavior -> move "__extends(a,b)" call to after function declaration
<Adrian_> The goal of the first change is to make it easier for beginners to understand the generated javascript as many tend to think (var func_name = function...) is the same as (function func_name...)
...
<jashkenas_work> Adrian_: the __extends actually has to happen first, to make executable class bodies work right with static inheritance.
<Adrian_> __extends can not happen before the function that it is extending is actually created
...
<jashkenas_work> Adrian_: yes, but executable class bodies preserve the order of their statements.
<Adrian_> it happens to work in how coffeescript generates it due to function _declarations_ always being executed first
<jashkenas_work> and __extends has to happen before the first statement.
<jashkenas_work> right, just so.
<Adrian_> __extends does not actually happen first
<Adrian_> if you put a breakpoint you will see it executing after the function declaration
<Adrian_> i am suggesting changing it to match how the actual execution is occurring to help avoid confusion
...
<Adrian_> jashkenas, to make what is happening in the class example clearer, add a namespace to the class names in the try coffeescript example
<Adrian_> NS.Animal, etc
<Adrian_> jashkenas_work, here is an example where you can see the difference: http://jsfiddle.net/alanning/yDnxL/
<Adrian_> if you move the __extends call to before the function expression, the example stops working.
<Adrian_> as you would expect
<Adrian_> the fact that coffeescript outputs function declarations instead keeps the code working but it doesn't match order of execution
<jashkenas_work> Adrian_: I understand the proposal.
The text was updated successfully, but these errors were encountered:
alanning
added a commit
to alanning/coffee-script
that referenced
this issue
Jul 20, 2011
Severity Low
Proposal
Move the generated function declaration to the first line of the generated class.
Issue
Coffeescript currently outputs the
__extends
call prior to the function declaration of generated classes while order of execution is actually the opposite.Rationale
While this currently causes no errors due to the happy coincidence that function declarations are always executed first, I believe implementing the proposed change avoids confusion for those trying to understand the generated code.
Example
An example of the issue can be found here: http://jsfiddle.net/alanning/yDnxL/
Reference
IRC #coffeescript channel discussion with jaskenas
Snipped for conciseness. Full chat log found here: http://irclogger.com/.coffeescript/2011-06-21#1308678991
The text was updated successfully, but these errors were encountered: