Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document class-methods-use-this #2130

Merged
merged 1 commit into from Nov 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Expand Up @@ -1254,6 +1254,39 @@ Other Style Guides
}
```

<a name="classes--methods-use-this"></a>
- [9.7](#classes--methods-use-this) Class methods should use `this` or be made into a static method unless an external library or framework requires to use specific non-static methods. Being an instance method should indicate that it behaves differently based on properties of the receiver. eslint: [`class-methods-use-this`](https://eslint.org/docs/rules/class-methods-use-this)

```javascript
// bad
class Foo {
bar() {
console.log('bar');
}
}

// good - this i used
class Foo {
bar() {
console.log(this.bar);
}
}

// good - constructor is exempt
class Foo {
constructor() {
// ...
}
}

// good - static methods aren't expected to use this
class Foo {
static bar() {
console.log('bar');
}
}
```

**[⬆ back to top](#table-of-contents)**

## Modules
Expand Down