javascript - JavaScript 构造函数改变值
问题描述
我有一个对你们来说可能真的很容易的问题。
例如,我得到了以下构造函数
class Example {
constructor(product, total) {
this.product= product;
this.total= total;
}
}
我现在如何将产品的价值更改为苹果?
我很感谢任何帮助。
解决方案
class Example {
constructor(product, total) {
this.product= product;
this.total= total;
}
}
let exampleObj = new Example('apple')
console.log(exampleObj.product) // 'apple'
推荐阅读
- jquery - 将 Laravel 变量传递给 Jquery 函数
- android - Google Play 控制台警告:未知验证 VALIDATE_APP_MESSAGE_ICON_NOT_UNIFORM
- java - PHP vs Java 加密密钥生成
- python - 动画队列pygame
- xml - XSLT:XML 第一个属性需要转换为具有第二个属性值的元素
- c# - 你能帮我解析这个 JSON 吗?
- android - 更新到 'com.android.tools.build:gradle:4.1.0' 后无法更改依赖配置的解析策略
- c++ - 这种模板部分专业化背后的意图是什么?
- java - JPAMetaModelEntityProcessor 无法使用特殊字符正常工作
- python - Python - 下载的视频文件的编解码器问题