Last active
July 25, 2016 15:01
-
-
Save savelee/41ae64c6c929d9e8f86333836b029b87 to your computer and use it in GitHub Desktop.
Example of destructuring
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
//ES5 | |
var myobject = { | |
name: "Sencha", | |
logo: { | |
small: { | |
png: 'http://path/to/small.png', | |
jpg: 'http://path/to/small.jpg' | |
}, | |
large: { | |
png: 'http://path/to/large.png', | |
jpg: 'http://path/to/large.jpg' | |
} | |
} | |
} | |
var { name, logo : { small : { jpg } } } = myobject; | |
console.log(name); //Sencha | |
console.log(small); // { png: "http://path/to/small.png", jpg: "http://path/to/small.jpg" } | |
console.log(jpg); //http://path/to/small.jpg |
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
//ES5 | |
var myobject = { | |
name: "Sencha", | |
logo: { | |
small: { | |
png: 'http://path/to/small.png', | |
jpg: 'http://path/to/small.jpg' | |
}, | |
large: { | |
png: 'http://path/to/large.png', | |
jpg: 'http://path/to/large.jpg' | |
} | |
} | |
} | |
var logo = myobject.logo.small.png; | |
var small = myobject.logo.small; | |
var company = myobject.name; | |
console.log(logo); //Sencha | |
console.log(small); // { png: "http://path/to/small.png", jpg: "http://path/to/small.jpg" } | |
console.log(company); //http://path/to/small.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment