const fatherJS = { age: 57, name: "Zhang San" }
Object.values(fatherJS)
//[57, "Zhang San"]
Object.entries(fatherJS)
//[["age", 57], ["name", "Zhang San"]]
Objects
Extract value
Computed property name
let event = 'click'
let handlers = {
[`on${event}`]: true
}
//Same as: handlers = { 'onclick': true }
Getters and setters
const App = {
get closed () {
return this.status === 'closed'
},
set closed (value) {
this.status = value ? 'closed' : 'open'
}
}
method
const App = {
start () {
console.log('running')
}
}
//Same as: App = { start: function () {···} }
Shorthand Syntax
module.exports = { hello, bye }
same below:
module.exports = {
hello: hello, bye: bye
}
Comments