I'm a systems programmer teaching myself javascript. Prototypal inheritance is completely new to me, so I could use some best practices advice here.
I made a simple game (breakout) for my first practice project. Here is a simple example of a game object.
function GameObject(sprite) {
this.xVelocity = 0;
this.yVelocity = 0;
this.x = 0;
this.y = 0;
this.sprite = sprite;
this.__defineGetter__('width', function() {
return sprite.width;
});
this.__defineGetter__('height', function() {
return sprite.height;
});
this.__defineGetter__('rect', function() {
return {
left :this.x,
top :this.y,
right :this.x + this.width,
bottom :this.y + this.height
};
});
}
Every object has an associate sprite and said sprite defines the width and height of the object. So, coming from C++, I defined a few of getters that depend on the sprite.
Any and all advice is obviously appreciated. Hopefully this example isn't overly trivial.