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
Carl Smith edited this page Jul 31, 2016
·
2 revisions
Whenever a CoffeeScript function is invoked, if no explicit return statement is executed, the function will implicitly return the value of the last expression to be evaluated in the function body. This is known as an implicit return.
The Issue
In CoffeeScript, (almost) everything is an expression. Blocks evaluate to the value of the last expression to be evaluated during the execution of the block. Implicit returns are consistent with this, however, the feature has always been controversial.
There is a (disputed) performance cost associated with generating and returning values that are immediately garbage collected where a function is invoked for its side effects, and the return value is not used.
Status
Within this project, no consensus has been established yet. The options are:
Keep the current behaviour.
Introduce syntax (for example, new function operators) that disable the feature on specific functions.
Introduce compiler options, so the feature can be disabled on specific files (possibly for a whole project).
Remove the feature entirely.
Option 4 is unlikely, as it is at odds with the design of CoffeeScript. Ashkenas has always favoured Option 1.
Background
This has been discussed many times. This is an incomplete list: