我的意思是,我很有可能忽略了一些简单的内容。
在代码中更容易解释,但我也会在这里尝试:
在该站点的节点和实时摘录功能中,第一次记录该对象将得出正确的结果5。
但是似乎在浏览器中,第一次记录对象实际上是在运行以下代码行之后才检索对象。这是预期的行为,还是我很胖?!
var Person5 = function(name, YoB, height, weight) {
this.name = name;
this.YoB = YoB;
this.height = height;
this.weight = weight;
};
var Athlete5 = function(name, YoB, height, weight, olympicGames, medals) {
Person5.call(this, name, YoB, height, weight);
this.olympicGames = olympicGames;
this.medals = medals;
};
Athlete5.prototype = Object.create(Person5.prototype);
Athlete5.prototype.addMedal = function() {
console.log('Number of medals before: ' + this.medals);
console.log('Adding medal');
this.medals++;
console.log('Number of medals before: ' + this.medals);
}
var nick = new Athlete5('Nick', 1983, 6.0, 14, 5, 5);
console.log(nick); // medals: 6 (in browser, it's 5 in the snippets)????
console.log(nick.medals); // medals: 5
nick.addMedal();
console.log(nick); // medals: 6