Skip to content

Instantly share code, notes, and snippets.

@k33g
Created October 11, 2011 14:29
Show Gist options
  • Save k33g/1278230 to your computer and use it in GitHub Desktop.
Save k33g/1278230 to your computer and use it in GitHub Desktop.
Creating A Private Scope By Extending The Public THIS Scope In JavaScript
#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()}"
@bennadel
Copy link

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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment