Last active
July 15, 2016 09:14
-
-
Save altescape/f4ef995f87ce8455db0c6702a90dd174 to your computer and use it in GitHub Desktop.
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
////// | |
// | |
// ES6 Object.assign ...or... The correct way to set settings, from defaults and options. | |
// | |
let defaults = { | |
a: 1, | |
b: 2, | |
c: 3 | |
}; | |
let options = { | |
b: 55 | |
}; | |
let settings = Object.assign({}, defaults, options); | |
console.log(settings); | |
////// | |
// | |
// ES6 for...of loop | |
// | |
users = ['Son House', 'Skip James', 'R.L. Burnside', 'Mississippi John Hurt']; | |
for(let user of users) { | |
console.log(user); | |
} | |
////// | |
// | |
// ES6 find | |
// | |
let recentTopics = [ | |
{ | |
title: "Semi-colons: Good or Bad?", | |
isLocked: true | |
}, | |
{ | |
title: "New JavaScript Framework Released", | |
isLocked: true | |
}, | |
{ | |
title: "ES2015 - The Shape of JavaScript to Come", | |
isLocked: false | |
} | |
]; | |
let topic = recentTopics.find( (topic) => !topic.isLocked ); | |
console.log(topic); | |
////// | |
// | |
// ES6 map data type | |
// | |
let user1 = { name: "Skip James" }; | |
let user2 = { name: "Mississippi John Hurt" }; | |
let mapSettings = new Map(); | |
mapSettings.set(user1, 5); | |
mapSettings.set(user2, 42); | |
console.log(mapSettings); | |
console.log(mapSettings.get(user1)); | |
////// | |
// | |
// ES6 container with unqiue values with set | |
// | |
let tags = new Set(); | |
tags.add("Mississippi John Hurt"); // 1 | |
tags.add("Skip James"); // 2 | |
tags.add("Doc Watson"); // 3 | |
tags.add("Richard Smith"); // 4 | |
tags.add("Jerry Reed"); // 5 | |
tags.add("Jerry Reed"); // 6 - shouldn't add as not unique | |
console.log("Total items", tags.size); // => 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment