I am playing with the HTML5 canvas element, using JS to draw some rectangles on it and then move them around, changing size and colors, etc. Currently I use mostly native JS, with jQuery for the jCanvas plugin to draw the shapes on the canvas. This is all working nicely, but I think the code could be improved.
Currently I store all rectangle properties in regular variables, like:
block1Height = 50;
block1Width = 50;
block1Color = '#000000';
block1X = 200;
block1Y = 100;
block2Height = 50;
block2Width = 50;
etc..
I am wondering whether it would be possible to just create instances of a 'block'-object. So I would have: an object called 'block', with properties 'height', 'width', 'color', etc. And then every time I create an instance of that object it has the default block properties.
The same goes for functions, I would like to do something like:
$block1.moveX(-100);
Is this possible in JS? What would be the correct way to do this?