【发布时间】:2022-01-06 12:47:55
【问题描述】:
const mark = {
firstName: `Mark`,
lastName: `Miller`,
fullName: this.firstName + this.lastName,
weight: 78,
height: 1.69
};
console.log(mark.fullName); // the result in console: NaN
【问题讨论】:
-
this指的是对象(窗口)的容器,而不是对象本身。如果要创建范围,请使用函数,或者更好的是使用类。window.firstName是未定义的,在 Javascript 中,undefined + undefined给出......“不是一个数字”NaN因为它试图将东西加在一起,它假设它应该在结束。
标签: javascript object