Created
September 1, 2012 10:51
-
-
Save tiye/3569541 to your computer and use it in GitHub Desktop.
OO is strange...
This file contains hidden or 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
| obj = require('./fake').obj | |
| global.show = console.log | |
| show (obj 'f1', 'xx') | |
| show (obj 'f2', 'qq') | |
| show (obj 'f3', 'ss') | |
| obj '.set', 'f3', (x) -> 'this is f3 ' + x | |
| show (obj 'f3', 'ss') | |
| obj2 = (obj '.clone', 'xx') | |
| show '\nnext...\n' | |
| show (obj2 'f1', 'xx') | |
| show (obj2 'f2', 'qq') | |
| show (obj2 'f3', 'ss') | |
| obj2 '.set', 'f3', (x) -> 'this is f3 ' + x | |
| show (obj2 'f3', 'more') | |
| obj3 = (obj '.clone', 'xx') | |
| show obj3 |
This file contains hidden or 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
| scope = | |
| f1: (x) -> 'this is f1 ' + x | |
| f2: (x) -> 'this is f2 ' + x | |
| exports.obj = (x, x2, x3=false) -> | |
| # show scope | |
| if scope[x]? then scope[x] x2 | |
| else if x is '.set' then scope[x2] = x3 | |
| else if x is '.get' then scope[x2] | |
| else if x is '.clone' then exports.obj | |
| else 'unknown message' |
This file contains hidden or 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
| ➤➤ coffee demo.coffee | |
| this is f1 xx | |
| this is f2 qq | |
| unknown message | |
| this is f3 ss | |
| next... | |
| this is f1 xx | |
| this is f2 qq | |
| this is f3 ss | |
| this is f3 more | |
| [Function] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You like coffee?