How to change all instances of object (class)?

0 like 0 dislike
5 views
Dynamically create the same instances of the class (this is mandatory) and add them to div ".out" through the created parameter instance.
But when I want to remove or change the properties of all ever created instances of the class NewLay - I don't know how to properly write the syntax. Maybe a prototype like that? The length property of the instances originally there :(



var lay;function NewLay() {this.html=$('1111111111');}lay = new NewLay();$('.out').append(lay.html);lay = new NewLay();$('.out').append(lay.html);lay = new NewLay();$('.out').append(lay.html);//// Как обратится ко всем созданным lay и удалить их код?//// !!! через .it_is_new_lay - ненужноalert(lay.length); /// undefinedlay.html.remove(); // удалим последний элемент.
by | 5 views

1 Answer

0 like 0 dislike
Dynamically create the same instances of the class (this is mandatory) ... to remove or change the properties of all ever created instances of the class NewLay - I don't know how to properly write the syntax. Maybe a prototype like that?
If you're talking about js objects, you will need somewhere to keep links to them. If no reference objects will live not long, they are the garbage collector will remove. But if he remove them is to change nothing.

If you want to change HTML elements with class it_is_new_lay, something like this:
$('.it_is_new_lay').each(function(){ let elem = $(this) elem.html( 'hello' + elem.html() ) })


lay = new NewLay(); lay = new NewLay(); lay = new NewLay();
every time you completely overwrite the contents of the variable, and you have there will remain only the most recent value.
by

Related questions

110,608 questions
257,186 answers
0 comments
33,932 users