Skip to content

Latest commit

 

History

History
74 lines (62 loc) · 1.01 KB

no-accessor-recursion.md

File metadata and controls

74 lines (62 loc) · 1.01 KB

Disallow recursive access to this within getters and setters

💼 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.

Examples

// ❌
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;
	}
}