How to reuse JavaScript class instances
P粉463824410
P粉463824410 2023-09-16 23:05:12
0
1
384

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 instances like person = new Person('Alice', 30);

But in my case I need to create many instances which will finish their work and be deleted but I want to reuse the instance after their work is finished. I know there is no API like this.resetInstance() but is there any way to achieve this?

P粉463824410
P粉463824410

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!