Expected 'this' to be used by class async method 'delete'
63 * @async
64 * @param {Number} id
65 */
66 async delete(id){} 67}
68
69/**
Expected 'this' to be used by class async method 'update'
55 * @param {Number} id
56 * @throws {Error('Entity not found')}
57 */
58 async update(id){} 59
60
61 /**
Expected 'this' to be used by class async method 'findOne'
47 * @returns {Object.object}
48 * @throws {Error('Entity not found')}
49 */
50 async findOne(){} 51
52 /**
53 * Updates an entity in the database
Expected 'this' to be used by class async method 'findMany'
38 * @async
39 * @returns {Array}
40 */
41 async findMany(){} 42
43
44 /**
Expected 'this' to be used by class async method 'create'
31 * @async
32 * @param {Object.object} data
33 */
34 async create(data){} 35
36 /**
37 * Finds all entities in the database
Expected 'this' to be used by class async method 'findError'
52 }
53 }
54
55 async findError(error, res){56 return res.json({ msg: `El error es ${error.name}, cuyo mensaje es: ${error.message}` })
57 }
58}
Expected 'this' to be used by class async method 'recover'
72
73 }
74
75 async recover(req, res){76
77 }
78
Expected 'this' to be used by class async method 'view'
49 return res.json({message : "cerraste tu cuenta"})
50 }
51
52 async view(req, res){53
54 return res.json(client)
55 }
Expected 'this' to be used by class async method 'logout'
42
43 }
44
45 async logout(req, res){46 res.set('client', '', {
47 expires: new Date(0),
48 })
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();