Last active
December 28, 2015 16:19
-
-
Save willscripted/7528658 to your computer and use it in GitHub Desktop.
Coffee - adventure with private method binding
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
class Thang | |
class Thing extends Thang | |
# isPrivate must exist above use in initialize | |
isPrivate = -> | |
return @things | |
initialize: -> | |
@things = true | |
# CS will assume local var if isPrivate is declared below this fn | |
isPrivate = isPrivate.bind(this) # werks | |
isAlsoPrivate = isAlsoPrivate.bind(this) # does not work, isAlsoPrivate undefined | |
isAlsoAlsoPrivate() # method would exist if reachable | |
isAlsoPrivate = -> | |
@things | |
isAlsoAlsoPrivate = -> | |
@things | |
stuff: -> | |
isPrivate() | |
x = new Thing | |
x.initialize() | |
alert x.stuff() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment