Reputation: 690
Can someone explain why the second example does not work:
var thisWorks = true || function () {};
var thisBreaks = true || () => {};
Upvotes: 0
Views: 55
Reputation: 220994
This is how the precedence of the various operators in ECMAScript 6 works.
There's a great explanation at http://typescript.codeplex.com/workitem/2360 that walks through each production in sequence.
Upvotes: 3
Reputation: 5112
use:
var thisBreaks = true || (() => {});
I think is related to operators priority.
var thisBreaks = true || (()=>{ }) ;
compile to javascript:
var thisBreaks = true || (function () { });
while
var thisBreaks = true || ()=>{};
compile to javascript:
var thisBreaks = true || ();
{ }
;
Try yourself here: http://www.typescriptlang.org/Playground
Upvotes: 1