I have one problem with OOP in JavaScript. In following example, when newObj.position.x is increased, newObj.x is not increased, despite the fact that I wrote this.x = this.position.x. Can you tell me why is that happening?
ClassOne = function( x, y )
{
this.x = x;
this.y = y;
};
ClassTwo = function( x, y, w, h )
{
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.position = new ClassOne( this.x, this.y );
this.x = this.position.x;
this.y = this.position.y;
}
var newObj = new ClassTwo( 10, 20, 30, 40 );
for ( var i = 0; i < 15; i++ )
{
newObj.position.x++;
console.log( newObj.x );
}
Result of the console.log is 10, 10, 10, 10, 10...