<script>
// 创建对象:
var person = {
firstName: "Bill",
lastName : "Gates",
id : 678,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};

// 显示来自对象的数据:
document.getElementById("demo").innerHTML = person.fullName();
</script>

 

https://www.w3school.com.cn/tiy/t.asp?f=js_this_method

 

 

 

第二中,this的变量是其他变量里面的

<script>
var person1 = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
var person2 = {
firstName:"Bill",
lastName: "Gates",
}
var x = person1.fullName.call(person2);
document.getElementById("demo").innerHTML = x;
</script>

https://www.w3school.com.cn/tiy/t.asp?f=js_this_call

 

https://www.w3school.com.cn/js/js_this.asp

相关文章:

  • 2021-10-30
  • 2021-05-24
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-08-08
  • 2021-11-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-12-02
  • 2022-12-23
相关资源
相似解决方案