Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created December 30, 2013 18:15
Show Gist options
  • Save joyrexus/8185631 to your computer and use it in GitHub Desktop.
Save joyrexus/8185631 to your computer and use it in GitHub Desktop.
Fat-arrow example
{ok} = require 'assert'
class Greet
constructor: (@greeting) ->
thin: -> @greeting
fat: => @greeting # see http://coffeescript.org/#fat-arrow
greet = new Greet 'hi'
ok greet.thin() is 'hi'
ok greet.fat() if 'hi'
# run a function in different context, thereby changing `this`/@
run = (f) -> f()
ok run(greet.thin) is undefined, 'since the thin arrow is context sensitive'
ok run(greet.fat) is 'hi', 'since the fat arrow preserves the original context'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment