5.对象的简化写法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
// ES6允许在大括号里面直接写入变量和函数,作为对象的属性和方法
let name = "张三";
let change = function () {
console.log("改变自己,改变全世界");
};
const obj = {
name, //相当于name:name
change, //相当于change:change
fn() {
//相当于 fn: function () {console.log("技能");}, 可以省略function关键字和:
console.log("技能");
},
};
console.log(obj);
</script>
</body>
</html>