class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
sayHello() {
console.log(`Hello, my name is ${this.name} and I'm ${this.age} years old.`);
}
}
I can create instance as person = new Person('Alice', 30);
But in my case i need to create many instances which will do their work and gets removed, but i want to reuse that instance once its work is done.
I know there is no api like this.resetInstance()
but is there any way to achieve this?
2
Answers
It most cases it does not worth the effort. But, if you want to do it, here you go:
Just make a cache.