In the first case "this" is window, because it's inherited from whatever scope you call it.
 
For example, in this case it won't be window:
!function() { ((n) => console.log(this))() }.call({foo: 'bar'})
 
In the second case "this" is window as well. But second case won't get executed, because you're running built-in String.prototype.repeat instead. :P
 
 
10.02.2014, 12:54, "Hemanth H.M" <hemanth...@gmail.com>:
I do understand Arrow functions are like built-in functions in that both lack .prototype and any [[Construct]] internal method.
 
But why does the scope refer to the global in case of :
 
```
String.prototype.repeat = (n) => Array(+n+1).join(this);

"ES6 ".repeat(3);

// will result in "[object Window][object Window][object Window]"
```
 
Whereas:
 
```
String.repeat = (n) => Array(+n+1).join(this);

"ES6 ".repeat(3) // Works fine resulting in "ES6 ES6 ES6"
 
``` 

Sorry if I'm missing something trivial. I did go through spec.

 
--
'I am what I am because of who we all are'
h3manth.com
-- Hemanth HM
,

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to