var Bar = function(){
}
Bar.prototype.drawBar = function(obj){
}
var bars = [];// Creating array
for (i = 0;i < ar.length ;i++){
bars[i] = [new Bar(ar[i],i)]; // Creating array of objects
bars[i].drawBar(i);// I am looking for something like this, Currently it doesn't work
}
I have something like this, How do I draw a bar, giving a reference/index, It should draw with the measurements
asked Apr 10, 2012 at 10:55
indianwebdevil
5,1277 gold badges42 silver badges53 bronze badges
1 Answer 1
You are trying to use bars[i] as if it was a Bar object, but it's an array of objects.
Use this to access the first object in the array:
bars[i][0].drawBar(i);
If you don't have any use for an array of arrays, just store the objects in the array directly:
bars[i] = new Bar(ar[i],i);
Then your original code to access the object works.
answered Apr 10, 2012 at 11:06
Guffa
703k112 gold badges760 silver badges1k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
bars[i] = new Bar(ar[i],i);. Or do you really want an array of arrays?