I want to loop on each object(building) of a class in javascript, like doing my own .each() jQuery function (because sometimes, I just need the first buildings, not the whole class). Is there a way to get the index of an element in a Javascript class ? Are the classes structured like an array so I can access to an element like $('.Building)[i] ?
my Class :
function Building (name, height, width) { this.name = name; this.height = height; this.width = width; }
When I add a building to the class :
var b1 = new Building("Building1", 1, 2); var b2 = new Building("Building2", 3, 4);
And then I want to display them by using a tool like
for (var i=0; i<$('.Building').length; i++){ displayOnMap($('.Building')[i]); }
Is it possible ? How should I code that ?
EDIT **
@MESSIAH: Sure you can make javascript classes, check here ;) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
@Ralph: No, I am not confusing, actually it works pretty well in my code. the .each() function is not only for the CSS class, but also working on JavaScript class made as seen above. It works like this :
$('.Building').each(function() { getData(this); });