💼 This rule is enabled in the ✅ recommended
config.
This rule prevents recursive access to this
within getter and setter methods in objects and classes, avoiding infinite recursion and stack overflow errors.
// ❌
const foo = {
get bar() {
return this.bar;
}
};
// ✅
const foo = {
get bar() {
return this.baz;
}
};
// ❌
class Foo {
get bar() {
return this.bar;
}
}
// ✅
class Foo {
get bar() {
return this.baz;
}
}
// ❌
const foo = {
set bar(value) {
this.bar = value;
}
};
// ✅
const foo = {
set bar(value) {
this._bar = value;
}
};
// ❌
class Foo {
set bar(value) {
this.bar = value;
}
}
// ✅
class Foo {
set bar(value) {
this._bar = value;
}
}