Created
June 20, 2016 08:02
-
-
Save FrankFang/d91ad7f1bf82b419de6d10dd93471feb to your computer and use it in GitHub Desktop.
Named function in CoffeeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Classes are the only place CoffeeScript generates named functions. | |
# This might seem messy, but the extra wrapping is necessary in order | |
# to have consistent behavior in IE. See the FAQ for more details: | |
# https://github.com/jashkenas/coffee-script/wiki/FAQ | |
class square | |
constructor: (x) -> return x * x # constructors require an explicit return | |
console.log square 5 # 25 | |
console.log square.name # square |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment