<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