Last active
December 4, 2018 19:24
-
-
Save jgwill/8d27285f1f6eec0c9f4d4af40d7cd324 to your computer and use it in GitHub Desktop.
@stcgoal Can we Destruct JavaScript object only using prop name?
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
var o = new Object(); | |
o.name = "myname in object"; | |
o.note = "a value we wont care about"; | |
o.description = "my description"; | |
var { description, name } = o; // Trying to destruct only with prop name to see if that can be done (It would be implied too :) ) | |
try { | |
console.log("Destruct description value : " + description); | |
console.log("Destruct name value : " + name); | |
} catch (err) { | |
console.log(err); | |
} | |
//@s SUccesss, you can destruct var {description,name} = o; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Handy :)
making that very light 👍