对象(object)是 JavaScript 最重要的数据结构。ES6 对它进行了重大升级
<script>
let title = "ES6从入门到学会";
let price = 25;
let publish = "小马出版社";
let book = {
title,
//等同于title: title
price: price,
publish,
toString() {
console.log(`<<${this.title}>> is ${price}元。`);
},
// 等同于toString: function ()...
};
book["lang"] = "简体中文";
console.log(book);
/*
* {title: "ES6从入门到学会", price: 25, publish:
* "小马出版社", lang: "简体中文", toString: function(){} }
*/
book.toString();//<<ES6从入门到学会>> is 25元。
</script>