首页 > 解决方案 > JavaScript 构造函数改变值

问题描述

我有一个对你们来说可能真的很容易的问题。

例如,我得到了以下构造函数

class Example {
   constructor(product, total) {
       this.product= product;
       this.total= total;
   }
}

我现在如何将产品的价值更改为苹果?

我很感谢任何帮助。

标签: javascript

解决方案


class Example {
   constructor(product, total) {
    this.product= product;
    this.total= total;
   }
}

let exampleObj = new Example('apple')
console.log(exampleObj.product) // 'apple'


推荐阅读