How to create a property that is an "object" javascript -


i trying create game object class contains sprite object. think i'm misunderstanding fundamental. edit: sprite class works gameobj class not.

function sprite(img) {     this.image = img;     this.w = img.width;       this.h = img.height; } function gameobj(img, x, y) {     var sp = sprite(img);      this.x = x;     this.y = y; } var acircle = new sprite(circle);  var aground = new gameobj(ground, 400,700); 

to call function constructor, use new keyword.

var sp = new sprite(img); 

this make this (inside function) refer "a new object" , not normal context (window since haven't specified context).

convention dictations constructor functions capitalised though (sprite).


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -