Skip to content

Instantly share code, notes, and snippets.

@FrankFang
Created June 20, 2016 08:02
Show Gist options
  • Save FrankFang/d91ad7f1bf82b419de6d10dd93471feb to your computer and use it in GitHub Desktop.
Save FrankFang/d91ad7f1bf82b419de6d10dd93471feb to your computer and use it in GitHub Desktop.
Named function in CoffeeScript
# 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