【发布时间】:2022-08-17 20:02:49
【问题描述】:
好的,所以我很确定我已经掌握了基础知识,但也许没有,因为我似乎无法理解为什么我的 bar() 函数不会从 foo() 接收更新的 bool 值。有人可以帮助我了解我在哪里出错了吗?
我确定这可能很愚蠢,但是在网上搜索并查看了一些示例之后,我似乎无法完全正确。
预期行为
bar() 应该输出 console.log(\'true\');
当前行为
bar() 当前输出 console.log(\'false\');
提前致谢。
class test {
constructor() {
this.bar();
}
foo(bool) {
bool = true;
return bool; // Return bool with \'true\' value
}
bar() {
let bool = false
this.foo(bool);
console.log(bool); // Console the updated value.
}
}
new test();
标签: javascript