Skip to content

Instantly share code, notes, and snippets.

@slikts
Created March 20, 2014 19:56
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 slikts/9672473 to your computer and use it in GitHub Desktop.
Save slikts/9672473 to your computer and use it in GitHub Desktop.
My least favorite thing about ES5
// I want to add multiple properties to a target object in one statement without adding extra variables to the current scope
// This can be done in ES6 with Object.assign:
var targetObj = {};
Object.assign({
a: 1,
b: 2
}, targetObj);
// Using ES5 it is impossible without an intermediary variable for the source object:
(function() {
var sourceObj = {
a: 1,
b: 2
};
Object.keys(sourceObj).forEach(function(key) {
targetObj[key] = sourceObj[key];
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment