java - Pure vs Impure 方法 ES6 类。我应该传递值还是应该将它们存储在对象中
问题描述
我 100% 确定这个话题之前讨论过,但我没能在谷歌上进行适当的搜索,所以我在这里。
通常,当我编写类时,我有一个特定的方法来做某事,并且在其中我构造每个步骤如下:
Class MyClass {
......
mainMethod() {
this.runValidation();
const val1 = this.method1();
const val2 = this.method2();
const val3 = this.method3(val1, val2);
const val4 = this.methid4(val1, val3);
......
return finalResult
}
}
我选择在当前对象中只存储一些特定的值。也许这种方式更好,或者我在更多地方使用它并且更容易访问,这取决于。
我的问题是什么是更好的做法。我刚刚在上面向您展示的那个,或者下面一段代码中的那个:
Class MyClass {
......
mainMethod() {
this.runValidation();
this.method1()
this.method2()
this.method3()
......
return this.finalResult
}
}
我在哪里不断更改当前对象的属性?
解决方案
推荐阅读
- git - 我想使用 EGit 将分支转换为 master
- bash - 这是在 cloudbuild.yaml 文件中编写 if..else 语句的正确方法吗?
- javascript - 在 Promise 中将数据异步写入 GCS
- javascript - 如何使用 date-picker bootstrap4 插件禁用每月 26 日到 30 日以及每个月的星期日
- c# - C# StreamReader 可以检查当前行号吗?
- docker - Docker 容器向 http 发送请求
- python - 编写灵活的正则表达式
- javascript - 如何修复“FirebaseError”类型的预期值,但在 Flutter Web 设置推送通知中得到“DomException”类型之一?
- firebase-realtime-database - 设备类型加湿器不显示湿度
- c++ - 无法使用 Visual Studio 生成 CMake 文件