Created
June 26, 2015 14:43
-
-
Save cdelaorden/651af67b3e93258f1d8e to your computer and use it in GitHub Desktop.
ES2015 - Destructuring object in argument list
This file contains hidden or 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
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