Created
October 11, 2011 14:29
-
-
Save k33g/1278230 to your computer and use it in GitHub Desktop.
Creating A Private Scope By Extending The Public THIS Scope In JavaScript
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
#from @bennadel experiment : http://www.bennadel.com/blog/2269-Creating-A-Private-Scope-By-Extending-The-Public-THIS-Scope-In-JavaScript.htm | |
class Human | |
constructor:(name)-> | |
@name = name | |
privateScope = Object.create @ | |
privateScope.nickName = "???" | |
@getNickName = -> | |
privateScope.nickName | |
@setNickName = (nickName)-> | |
privateScope.nickName = nickName | |
sayHello:-> | |
console.log "Hello #{@getNickName()}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very cool ! I only recently watched a CoffeeScript talk at jQuery Conference 2011. Seems like it can add some nice functionality, especially the string interpolation!!