override setter
2022年5月1日小于 1 分钟
override setter
Question
What does the code snippet to the right output by console.log
?
Snippet
class A {
val = 1
get foo() {
return this.val
}
}
class B {
val = 2
set foo(val) {
this.val = val
}
}
const a = new A()
const b = new B()
console.log(a.foo)
console.log(b.foo)
b.foo = 3
console.log(b.val)
console.log(b.foo)