Last active
May 24, 2018 11:29
-
-
Save amorfati0310/511c2fde3b4403bb1a9e391c2fa81292 to your computer and use it in GitHub Desktop.
this
This file contains 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
//2초뒤에 'codesquad'가 출력되도록 코드를수정하세요. (출력은 printMyname을 통해서 할 수 있음) | |
//(a,b객체를 직접 부를 수 없음. bind,call 등을 사용해야 함) | |
let a = { | |
run() { | |
setTimeout( ()=> { | |
const name = this.getName(); | |
printMyname(name) | |
},10); | |
} | |
} | |
let b = { | |
start(printMyname) { | |
setTimeout(function(){ | |
a.run.call(b) | |
},10); | |
}, | |
getName() { | |
return 'codesquad' | |
} | |
} | |
let printMyname = (name) => console.log(name); | |
b.start(printMyname); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
설명
a.run()이 불릴떄 .call(b)로 b를 호출해줍니다
내부에서 printMyname을 closer로 접근 가능하므로 이를 이용해서 내부에서 codeSquad를 출력해줍니다.
혹은 printMynmae(a.run.call(b))