Skip to content

Instantly share code, notes, and snippets.

@tiye
Created September 1, 2012 10:51
Show Gist options
  • Select an option

  • Save tiye/3569541 to your computer and use it in GitHub Desktop.

Select an option

Save tiye/3569541 to your computer and use it in GitHub Desktop.
OO is strange...
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
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'
➤➤ 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]
@unionx
Copy link
Copy Markdown

unionx commented Sep 1, 2012

You like coffee?

@tiye
Copy link
Copy Markdown
Author

tiye commented Sep 2, 2012

@unionx 我喜欢 V8 这个平台, 上面让人舒适的语言很少.

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