对象值未更新,也不知道为什么

时间:2019-02-18 18:04:41

标签: javascript

我有一个构造函数来创建帐户并管理其数据,如下所示:

        function account(fname, lname){
            this.checking = 0;
            this.savings = 0;
            this.total = this.checking + this.savings;
            this.openDate = new Date();
            this.transactions = [];
            this.firstName = fname;
            this.lastName = lname;
            this.deposit = (account, amount) => {
                account += amount;
            };
            this.withdrawal = (account, amount) => {
                account -= amount;
            };
        }

...但是我遇到的问题是,每当我尝试使用存款或取款功能时,相关值都不会更新。我这样写出来:

var client = new account("Name", "Name");
client.deposit(client.checking, 5000);

...仍然没有骰子。有什么建议吗?

编辑:

我一直遇到IDE问题,但是我们首先要解决这个问题(使用NetBeans)。

1 个答案:

答案 0 :(得分:1)

字符串和数字是Javascript中的不可变属性,不能通过引用进行修改。您应该改为修改实际的对象实例值

{{1}}