-
-
Save qubyte/43e0093274e793cc82ba to your computer and use it in GitHub Desktop.
var a = true; | |
var test = () => console.log(this.a); | |
test(); // true | |
var test2 = test.bind({ a: false }); | |
test2(); // Canary: false, Firefox: true |
@webbedspace -
Regarding -
let obj = {
method: () -> this.foo + 7
};
(I removed the semicolon, as it would probably throw a SyntaxError)
I think this
would be window
in this case.
Just like -
this.foo = "r";
let obj = {
bar: this.foo
};
Would be {bar: "r"}
.
Am I wrong?
@phistuck pay attention to the arrow, the thin one does not bind the context at creation time. this
would be the expected object in that method.
Wow, for some reason I got no notifications for this thread. Sorry all. @domenic is quite right. This was me looking at an experimental feature, and I was jumping the gun somewhat. Fat-arrows are only partially implemented in the version of V8 in that version of Canary and full support will come in time.
The two versions were not picked to be equivalent in terms of their development process. They just happened to be the browsers I was testing with.
I presume the author is testing this by enabling "experimental JavaScript features" in Canary. Such features are experimental and not meant to reflect actual usable up-to-spec JavaScript. Comparing them against Firefox's on-by-default features is not a fair comparison.
Also on an unrelated note the correct counterpart to Canary is Nightly; the correct counterpart to Aurora is Dev Channel.