javascript - Create several instances of a module with different values -


this simple problem need create javascript equivalent n instances of 'class' state must totally separate.

like:

var car = new car('ford'); var car = new car('toyota'); 

how can achieve this?

you can use array object store them:

var cars = []; cars.push(new car('ford')); cars.push(new car('toyota')); cars[0].beep(); 

you can iterate on stored instances using for loop:

for (var = 0; < cars.length; i++) { var car = cars[i]; car.beep(); } 

Comments

Popular posts from this blog

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -