Objects

Extract value

const fatherJS = { age: 57, name: "Zhang San" }
Object.values(fatherJS)
//[57, "Zhang San"]
Object.entries(fatherJS)
//[["age", 57], ["name", "Zhang San"]]

Computed property name

let event = 'click'
let handlers = {
  [`on${event}`]: true
}
//Same as: handlers = { 'onclick': true }

See: Object Literals Enhanced

Getters and setters

const App = {
  get closed () {
    return this.status === 'closed'
  },
  set closed (value) {
    this.status = value ? 'closed' : 'open'
  }
}

See: Object Literals Enhanced

method

const App = {
  start () {
    console.log('running')
  }
}
//Same as: App = { start: function () {···} }

See: Object Literals Enhanced

Shorthand Syntax

module.exports = { hello, bye }

same below:

module.exports = {
  hello: hello, bye: bye
}

See: Object Literals Enhanced

Comments