意外标识符 javascript 对象方法,当我运行它时,我声明函数的第一行出现错误?


var john = {
fullName: 'John Smith',
mass: 230 / 2.2,
height: 1.5
calcBmi: function(bmi) {
this.johnBmi = this.height * this.height / this.mass;
}
}

你错过了高度后面的逗号。代码变为(为了可读性(:

var john = {
fullName: 'John Smith',
mass: 230/2.2,
height: 1.5,
calcBmi: function(bmi) {
this.johnBmi = this.height * this.height / this.mass;
}
};

你错过了高度后面的逗号。

var john = { 
fullName: 'John Smith',
mass: 230 / 2.2,
height: 1.5,
calcBmi: function(bmi) {
this.johnBmi = this.height * this.height / this.mass;
}
}

现在试试这个。

最新更新