Skip to content

Instantly share code, notes, and snippets.

@goonoo
Last active August 29, 2015 14:06
Show Gist options
  • Save goonoo/384cfe2cc14c09bdb5b8 to your computer and use it in GitHub Desktop.
Save goonoo/384cfe2cc14c09bdb5b8 to your computer and use it in GitHub Desktop.
bind this on coffeescript class
async_call = (callback) ->
setTimeout callback, 1
class ThisPlus
# 생성자
constructor: ->
# javascript의 this.do_something과 동일
@do_something()
callback = => # => 를 통해 내부 함수에 this를 binding
@do_something()
async_call(callback)
# ThisPlus class의 do_something method
do_something: ->
console.log "DO"
@goonoo
Copy link
Author

goonoo commented Sep 16, 2014

실행해보면 당연히 do_something이 두 번 불린다.

http://codepen.io/mctenshi/pen/iDdlo

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