标签:function 之间 tin text 增加 hello inter set java
<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>
标签:function 之间 tin text 增加 hello inter set java
原文地址:https://www.cnblogs.com/weixin2623670713/p/13334624.html