Javascript 对象构造函数语法错误

Javascript 对象构造函数语法错误,javascript,Javascript,在学习JS的过程中。。。这是从JS的第一天开始的第二周,我在语法方面遇到了很大的问题 function Customer(name, street, city, state, email, balance) { this.name = name; this.street = street; this.city = city; this.state = state; this.email = email; this.balance = balance

在学习JS的过程中。。。这是从JS的第一天开始的第二周,我在语法方面遇到了很大的问题

function Customer(name, street, city, state, email, balance) {
    this.name = name;
    this.street = street;
    this.city = city;
    this.state = state;
    this.email = email;
    this.balance = balance;
    this.payDownBal = function(amtPaid) {
        this.balance -= amtPaid;
    };
    this.addToBa = function(amtCharged) {
        this.balance += amtCharged;
    };
}
var cust2 = new Customer("Sally Smith", "234 Main ", "Pittsburgh", "PA", "ssmith@aol.com", 0.00);

cust2.addToBal(15.50);

Customer.prototype.isCreditAvail = true;

Customer.prototype.toString = function() {
    return this.name + " lives at " + this.street + " in " +
        this.city + " " + this.state + " email : " + this.email +
        " and has a balance of $ " + this.balance.toFixed(2) + "Creditworty : " + this.isCredAvail;
}
document.write(cust2.toString());

我找不到错误…能帮我吗

仔细看第11行,你的函数声明:

this.addToBa = function (amtCharged) {
第17行:

cust2.addToBal(15.50);
这是一个打字错误,第11行的“addToBa”应该是“addToBal”


(另外,还有另一个输入错误不允许toString函数中引用“isCreditAvail”真布尔值,在第3行到最后一行…将“this.isCreditAvail”更改为“this.isCreditAvail”)。

好吧,仔细看第11行,函数声明:

this.addToBa = function (amtCharged) {
第17行:

cust2.addToBal(15.50);
这是一个打字错误,第11行的“addToBa”应该是“addToBal”

(另外,还有另一个输入错误不允许toString函数中引用“isCreditAvail”真布尔值,在第3行到最后一行…将“this.isCreditAvail”更改为“this.isCreditAvail”)。

您犯了一个简单的错误。 您定义了addToBa()函数,正在调用未定义的函数addToBal()

更改第17行以调用函数addToBa()。(或将函数声明更改为addToBal())。

您犯了一个简单的错误。 您定义了addToBa()函数,正在调用未定义的函数addToBal()


更改第17行以调用函数addToBa()。(或将函数声明更改为addToBal())。

什么使您认为有错误?你收到错误消息了吗?如果是,是什么?堆栈溢出不是一个您可以发布一大块代码并期望其他人为您修复代码的地方。解释问题并提供相关信息。看。下一篇文章会更详细,谢谢你的建议。你不必等到下一篇文章,你可以这样写:)你怎么会认为有错误?你收到错误消息了吗?如果是,是什么?堆栈溢出不是一个您可以发布一大块代码并期望其他人为您修复代码的地方。解释问题并提供相关信息。请参阅。下一篇文章将更加详细,感谢您的建议您不必等到下一篇文章,您可以选择这篇:)