dwyl / learn-javascript

A Series of Simple Steps in JavaScript :-)
Other
64 stars 15 forks source link

ES6 Object Litteral Shorthand Notation? #15

Open nelsonic opened 8 years ago

nelsonic commented 8 years ago

This is a reasonably good/useful feature: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015 it allows us to do the following:

// imagine that there are already variables in your script/app for name and email
var obj = {
  name,
  email
}

instead of having to type out the values for the fields in the Object:

// imagine that there are already variables in your script/app for name and email
var obj = {
  name: name,
  email: email
}

The JavaScript engine infers what the values are given the names of the keys in the Object...

Given that most browsers don't support this... es6-object-literal-shorthand-notation I will be using it selectively...