ES 6 Title

Object Literal Enhancement

ES6 brought some advancement to javascript, one of these additions has to do with Object Literals.

“A JavaScript object literal is a comma-separated list of name-value pairs wrapped in curly braces. Object literals encapsulate data, enclosing it in a tidy package. This minimizes the use of global variables which can cause problems when combining code.”

Object literal enhancement is the opposite of destructuring. Therefore, It is the process of restructuring or putting back together. As you can see, with object literal enhancement, we can grab variables from the global scope and turn them into an object. To illustrate this point, look at the following example:

var name = "Bobby"
 var Phrase = "Dammit Bobby"
 var kothQuote = {name,elevation}
 console.log(kothQuote) // {name: "Bobby", Phrase: "dammit Bobby"}
 name and elevation are now keys of the kothQuote object.
 We can also create object methods with object literal enhancement or restructuring:
 var name = "Bobby"
 var kothQuote = "That's my purse! I don't know you!"
 var print = function() {
 console.log(${this.name} says ${this.Phrase} )
 }
 var kothQuote= {name,Phrase,print}
 kothQuote.print() // Bobby says That's my purse!  I don't know you!"


Notice we use this to access the object keys. As a result of the enhancement, when defining object methods, it is no longer necessary to use the function keyword.

Most of this came from my O’Reilly Book on Node.js apps.

Also here is a better written article, I shouldn’t do this and link to things I am creating, but I am doing this mostly for fun, I will start planning out my articles better in the future to give more learning details. More Info

Leave a Reply