Can someone explain why the second example does not work:
var thisWorks = true || function () {};
var thisBreaks = true || () => {};
Can someone explain why the second example does not work:
var thisWorks = true || function () {};
var thisBreaks = true || () => {};
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
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.