Expected 'this' to be used by class async method 'transferFunds'
13 return this.web3.eth.getBalance(address);
14 }
15
16 async transferFunds(from, to, amount) {17 // Implement transfer logic using Web3
18 }
19}
Description
If a class method does not use this
, it can sometimes be made into a static function. If you do convert the method into a static function, instances of the class that call that particular method have to be converted to a static call as well (MyClass.callStaticMethod())
Bad Practice
class Person {
sayHi() {
const greeting = document.createElement("div");
greeting.innerText = "Hello!";
document.appendChild();
}
}
const person = new Person();
person.sayHi();
Recommended
class Person {
static sayHi() {
const greeting = document.createElement("div");
greeting.innerText = "Hello!";
document.appendChild();
}
}
Person.sayHi();