A static method in a class is a method that has no relation to other properties and methods of that class and static methods can’t access the properties and methods of the class.
If we want to access the static method, then we can access the static method with the class name directly. No need for the help of class instances described below.
class Man { constructor(name, age) { this.name = name; this.age = age; } play() { console.log(`my name is ${this.name}.`) } get setPerson() { console.log(`I am ${this.name} & my age is ${this.age}`) } set setPerson(name) { this.name = name; } static personStaic(muhin, mushi) { return muhin.age === mushi.age; } } let person = new Man("mozahedu", 28); console.log(person); // for setter method person.setPerson = "shahidul"; console.log(person.setPerson); let muhin = new Man("muhin", 16); let mushi = new Man("mushi", 12); // log the static method ... console.log(Man.personStaic(muhin, mushi));
Post a Comment