Skip to content

Instantly share code, notes, and snippets.

@altescape
Last active July 15, 2016 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altescape/f4ef995f87ce8455db0c6702a90dd174 to your computer and use it in GitHub Desktop.
Save altescape/f4ef995f87ce8455db0c6702a90dd174 to your computer and use it in GitHub Desktop.
//////
//
// 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