oop - creating numbered objects from a constructor in javascript -
i have constructor makes squares.
i code automatically create squares constructor using loops , name them square1, square2, square3 ect.
eg.
for (n=1; n < x; n++){ var square(n) = new square(); }
is possible?
if how , how refer them in loop - square(n)?
i'm new programming, oop , javascript sorry if ovb. in advance
that's arrays for:
var squares = new array(); (var n = 1; n < x; n++) { squares.push( new square() ); }
now you're able access them zero-based index:
squares[0].somemethod(); // etc..
to iterate on squares in array:
for (var = 0; < squares.length; i++) { squares[i].somemethod(); }
Comments
Post a Comment