JAVACAFE-JS2016 / ES6

4 stars 0 forks source link

object arrow 에서의 this #2

Open heejunghwang opened 8 years ago

heejunghwang commented 8 years ago

object arrow 에서의 this는 왜 window일까요?

var obj = { a:()=>{console.log(this)} } obj.a() //result : window

heejunghwang commented 8 years ago

http://www.2ality.com/2012/04/arrow-functions.html 번역해서 확인해볼 것

youngbeomrhee commented 7 years ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#Arrow_functions

예제의 var foo = (() => this); 에 하나를 더 추가해서 var fooFn = function() { return this; }; 두개를 비교해보면 이해가 편함 결론적으로 모호성이 없어짐