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
Post a Comment