Skip to content

Instantly share code, notes, and snippets.

@andreineculau
Last active December 15, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreineculau/5284402 to your computer and use it in GitHub Desktop.
Save andreineculau/5284402 to your computer and use it in GitHub Desktop.
scope in JS
m =
x: 1
getX: -> @x
getX = m.getX
console.log m.getX(), getX() # 1 undefined
m =
x: 1
getX: -> @x
getX = m.getX.bind m
console.log m.getX(), getX() # 1 1
_ = require 'lodash'
m =
x: 1
getX: -> @x
_.bindAll m
getX = m.getX
console.log m.getX(), getX() # 1 1
# sometimes you see bindAll calls in a class' constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment