首页 > 其他 > 详细

字典里面 值对应是函数的用法

时间:2020-07-01 14:28:15      阅读:55      评论:0      收藏:0      [点我收藏+]

<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

字典里面 值对应是函数的用法

原文:https://www.cnblogs.com/kaibindirver/p/13218903.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!