Skip to content

Instantly share code, notes, and snippets.

@savelee
Last active July 25, 2016 15:01
Show Gist options
  • Save savelee/41ae64c6c929d9e8f86333836b029b87 to your computer and use it in GitHub Desktop.
Save savelee/41ae64c6c929d9e8f86333836b029b87 to your computer and use it in GitHub Desktop.
Example of destructuring
//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
//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