Skip to content

Instantly share code, notes, and snippets.

@cdelaorden
Created June 26, 2015 14:43
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 cdelaorden/651af67b3e93258f1d8e to your computer and use it in GitHub Desktop.
Save cdelaorden/651af67b3e93258f1d8e to your computer and use it in GitHub Desktop.
ES2015 - Destructuring object in argument list
function foo({movieCount}){
console.log(movieCount);
//modify provided obj? no way
movieCount = 0;
}
function oldFoo(obj){
console.log(obj.movieCount);
//modify provided obj? yes it's possible and dangerous
obj.movieCount = 0;
}
let obj = { id: 5, name: 'John Hughes', movieCount: 5};
foo(obj);
oldFoo(obj);
console.log(obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment