[英]How to set value in object constructor?
我的脚本有问题。
为什么我的这个 object 的构造函数不知道 wynik1 的值正在改变并且总是返回“this.A”而不是改变它?
var wynik1 = (liczba1 / liczba2) * profil;
function potatos(name, moc, square, A, B, C, D, price) {
this.name = name;
this.moc = moc;
this.square = square;
this.A = A;
this.B = B;
this.C = C;
this.D = D;
this.price = function() {
if (wynik1 < 18000) {
return this.A;
}
if (wynik1 < 10000) {
return this.B;
}
if (wynik1 < 5000) {
return this.C;
}
if (wynik1 < 3000) {
return this.D;
}
};
}
const animus = new potatos('nameone', 370, 1.7, 7533, 5670, 4800, 4200);
const anomus = new potatos(' olar', 470, 1.7, 7800, 6900, 5260, 4630);
const atopuso = new potatos('komisuslar', 780, 1.7, 7900, 6080, 5450, 4815);
var prices = (function moc() {
if (liczba4 == "A") {
return animus.price(4200, 4000, 3800, 3600);
}
if (liczba4 == "B") {
return anomus.price(4000, 4200, 4600, 5000);
}
if (liczba4 == "C") {
return atopuso.price(4200, 4500, 4800, 5300);
}
})();
这是因为您在if(wynik1 <18000)
中指定的条件在大多数情况下都是正确的,请改用此条件:
if(wynik1 <18000 && wynik1 >= 10000)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.