【发布时间】:2020-05-07 21:57:15
【问题描述】:
我在 Brackets 中使用 JS,当我刷新此部分时,Carbo 的值在控制台中是正确的。但是,当我在那个 console.log 中尝试这个时,谷歌控制台只写了 ,undefined'。
为什么以及我该如何解决这个问题?
这是我的练习计划。
var Foods = function(name, priceWithDollar, makingTimeMin) {
this.name = name;
this.priceWithDollar = priceWithDollar;
this.makingTimeMin = makingTimeMin;
}
Foods.prototype.priceChangeToHUF = function() {
console.log(this.priceWithDollar * 326);
}
var carbonara = new Foods('Carbonara', 10.91, 10);
carbonara.priceChangeToHUF();
console.log('The carbonara\'s price is ' + carbonara.priceChangeToHUF() + '.');
感谢您的帮助。
亚当
!还有一件事! 就在此时,当我写下这些台词时,我想到了一些东西。 原型 (326) 的值实际上不是动态的。 但我有一个想法。当我检查 ,1 美元到 huf' 时,我必须从第一个谷歌页面写下这个实际值。
我该如何开始?
谢谢!
【问题讨论】:
标签: javascript function constructor function-constructor