-3
マイコード:"this"を除いたメソッドを入れる場所は?
class DoIt {
city() {
// others operations...
const number = 5; // from operations
const amount = this.getAmount (number);
// others operations...
}
street() {
// others operations...
const number = 10; // from operations
const amount = this.getAmount (number);
// others operations...
}
getAmount (number) {
return number * 10 * 3.14/3; // example...
}
}
私は私のコードをチェックするために、「eslint」を使用し、私はエラーがあります:
error Expected 'this' to be used by class method 'getAmount' class-methods-use-this
だから、「この」せずにメソッドを置くことを?このコードはクラスにとって重要なので、ヘルパークラスを作成しないでください。
このメソッドは重要ではないのでしょうか?他の言語のOOPでは、クラスメソッドに 'this'を含まないメソッドが存在する可能性がありますか?
あなたは 'this.number(数)'とはどういう意味ですか?あなたのクラスに関数 'number()'はありませんか? – edkeveked
申し訳ありませんが間違いでした。私は私の質問を更新しました。 – maspib
エラーのためのドキュメントは、それをとてもうまく説明しています。https://eslint.org/docs/rules/class-methods-use-this – jmargolisvt