Heh heh the second case was enlightening. If I need to bind it to prototype's context, it's not possible because it's lexical, but how does one extend prototype chain with fat arrow functions?
On Mon, Feb 10, 2014 at 2:41 PM, Alex Kocharin <[email protected]> wrote: > > 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" <[email protected]>: > > 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. > > [spec]( > http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax) > > -- > *'I am what I am because of who we all are'* > h3manth.com <http://www.h3manth.com/> > *-- Hemanth HM * > , > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > > -- *'I am what I am because of who we all are'* h3manth.com <http://www.h3manth.com> *-- Hemanth HM *
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

