Last active
December 15, 2015 15:49
-
-
Save andreineculau/5284402 to your computer and use it in GitHub Desktop.
scope in JS
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
m = | |
x: 1 | |
getX: -> @x | |
getX = m.getX | |
console.log m.getX(), getX() # 1 undefined |
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
m = | |
x: 1 | |
getX: -> @x | |
getX = m.getX.bind m | |
console.log m.getX(), getX() # 1 1 |
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
_ = 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