Blogger Information
Blog 250
fans 3
comment 0
visits 322903
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Vue自学:关于ES6的对象增强写法
梁凯达的博客
Original
771 people have browsed it

<!DOCTYPE html>

<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>关于ES6的对象增强写法</title>
</head>
<body>

</body>
<script type="text/javascript">
//使用ES6的写法,需要注意部分的浏览器并不兼容ES6
//所以需要使用工具,将ES6的代码同步成被兼容的ES5的写法
//ES6之前的属性写法
let name = ‘way’
let age = 18
// let obj = {
// name:name,
// age:age
// }
//ES6以后的写法
//直接往对象当中写入变量名称,会自动识别变量是否存在
//但当加入了xx:后,:会将属性变为新的需要定义的属性
let obj = {
name,
age
}
console.log(obj)

//ES6之前的函数写法
let obj1 = {
eat:function(){
console.log(1);
},
}
//ES6之后的函数写法
let obj2 = {
eat(){
console.log(3);
}
}
obj1.eat()
obj2.eat()
</script>
</html>

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post