Skip to content
This repository has been archived by the owner on Feb 19, 2018. It is now read-only.

Feature: Implicit Return

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:

  1. Keep the current behaviour.
  2. Introduce syntax (for example, new function operators) that disable the feature on specific functions.
  3. Introduce compiler options, so the feature can be disabled on specific files (possibly for a whole project).
  4. 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:

Clone this wiki locally