Last active
August 29, 2015 14:06
-
-
Save goonoo/384cfe2cc14c09bdb5b8 to your computer and use it in GitHub Desktop.
bind this on coffeescript class
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
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
실행해보면 당연히
do_something
이 두 번 불린다.http://codepen.io/mctenshi/pen/iDdlo