Pattern: Duplicate class member declaration
Issue: -
When class members have the same name, the last declaration silently overwrites previous ones. This can lead to unexpected behavior, especially when mixing methods and properties with the same name.
Example of incorrect code:
class A {
foo() {
console.log("foo");
}
foo = 123; // Overwrites foo method
}
class B {
bar() {}
bar() {} // Duplicate method
}
Example of correct code:
class A {
foo() {
console.log("foo");
}
bar = 123;
}
class B {
bar() {}
baz() {}
}