I have an object like below
function obj() {
this.cellSize = 50;
this.createBlock = function() { // creates a block object
this.x = 0;
this.y = 0 - (this.cellSize * 1.5);
this.baseVelocity = 1;
this.velocity = this.baseVelocity;
return this;
};
this.activeBlock = this.createBlock(); // active block object
this.nextBlock = this.createBlock(); // next block object
}
When I check obj.activeBlock I am not getting the object which should be returned from obj.createBlock?
Thanks,
newkeyword?var a = new obj(); console.log(a.activeBlock);.obj.activeBlockis the same asobj, rather than the object having what is outlined increateBlock?obj.activeBlock..." Seems you're guessing at howthisin JavaScript works..activeBlocktoobj. Theobjis a function, andthisisn't a reference to it.