Last active
December 5, 2016 23:37
-
-
Save elsassph/47c3fb9e6aa59a1ab0a8 to your computer and use it in GitHub Desktop.
ES2015 / babel vs Haxe code generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = [1,2,3]; | |
var acc = 0; | |
for (const v of a) { | |
acc += v; | |
} | |
// want clean code? use Array.reduce | |
console.log(acc); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [1, 2, 3]; | |
var acc = 0; | |
var _iteratorNormalCompletion = true; | |
var _didIteratorError = false; | |
var _iteratorError = undefined; | |
try { | |
for (var _iterator = a[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | |
var v = _step.value; | |
acc += v; | |
} | |
} catch (err) { | |
_didIteratorError = true; | |
_iteratorError = err; | |
} finally { | |
try { | |
if (!_iteratorNormalCompletion && _iterator["return"]) { | |
_iterator["return"](); | |
} | |
} finally { | |
if (_didIteratorError) { | |
throw _iteratorError; | |
} | |
} | |
} | |
console.log(acc); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [1,2,3]; | |
var acc = 0; | |
// unlike babel, Haxe knows it's an Array<Int> iteration | |
for (v in a) { | |
acc += v; | |
} | |
trace(acc); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [1,2,3]; | |
var acc = 0; | |
var _g = 0; | |
while(_g < a.length) { | |
var v = a[_g]; | |
++_g; | |
acc += v; | |
} | |
console.log(acc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In ES6 it should be closer to
Which compiles nicely to