Last active
September 1, 2016 00:32
-
-
Save richard-to/70049650cf58f1858b8cd38528c07a3c to your computer and use it in GitHub Desktop.
ES6 Features - based on examples from http://es6-features.org/
This file contains 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
// Constants | |
const test_const = 1; | |
// Scoped variables - use `let` for local scope | |
let callbacks = []; | |
for (let i = 0; i < 3; ++i) { | |
callbacks[i] = function() { return i; }; | |
} | |
// Arrow functions | |
let plus_one = [1, 2, 3, 5].map(v => v + 1); | |
let fives = []; | |
[1, 4, 5, 6].forEach(v => { | |
if (v % 5 === 0) { | |
fives.push(v); | |
} | |
}); | |
// Arrow functions + Lexical "this" - A bit confusing actually...Ok, so arrow functions do not use their own "this" | |
this.fives = []; | |
this.nums = [1, 4, 5, 6]; | |
this.nums.forEach((v) => { | |
if (v % 5 === 0) { | |
this.fives.push(v); | |
} | |
}); | |
// Function defaults | |
function f_with_defaults(x, y=7, z=42) { | |
return x + y + z; | |
} | |
f_with_defaults(1) === 50; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment