ES6语法
<script type="text/javascript">
var name = "abc";
var age = 13;
var obj = {
// name 属性名=name 属性值,
name : name,
age : age,
}
console.log(obj);
// ES6
var name = "abc";
var age = 13;
var obj = {
name,
age,
}
console.log(obj);
</script>
<script type="text/javascript">
var obj = {
name:"张三",
SayHello:function(){
console.log(this.name);
}
}
obj.SayHello();
// Es6
var obj = {
name:"张三",
SayHello(){
console.log(this.name);
}
}
obj.SayHello();
</script>
<script type="text/javascript">
var obj = {
name:"hello",
sayHello:function(){
setInterval(function(){
console.log(this.name)
},1000)
}
}
obj.sayHello()
// Es6箭头函数
var obj = {
name:"hello",
sayHello:function(){
// 在参数和函数体之间增加函数
setInterval(()=>{
console.log(this.name)
},1000)
}
}
obj.sayHello()
</script>