How can I/Is it possible to enumerate all the objects that have been added to a canvas element, and iterate over them?
By the way - jCanvas is available.
Canvas is just a bitmap and doesn't use objects - only pixels after rasterizing the shapes that has been defined.
You can however make you own objects representing what is being drawn to the canvas and store those objects in an array. This way you can iterate, alter and re-draw the objects for canvas (or even export them as SVG, PDF, XML, JSON etc. if needed).
An object can be as simple as:
function Rect(x, y, w, h) {
this.x = x;
this.y = y;
this.width = w;
this.height = h;
// example render
this.render = function(ctx) {
ctx.beginPath();
ctx.rect(this.x, this.y, this.width, this.height);
ctx.stroke();
}
}
Then allocate it:
var shapes = [];
shapes.push(new Rect(10, 10, 200, 200));
shapes.push(new Rect(50, 50, 100, 150));
When iterating you can render them, alter them and so forth:
for(var i = 0, shape; shape = shapes[i++];) {
shape.render(ctx); // render this shape
shape.x += 5; // move 5 pixels to right
}
Of course, simplified and not optimized here but you should get the idea.