I defined a class like this at first:
function mapTile(nx,ny)
{
//members
this.x = nx;
this.y = ny;
//methods
this.prototype.visible = function(){return true;};
this.prototype.getID = function(){return y*tiles_per_line+x;};
this.prototype.getSrc = function(){return 'w-'+this.getID+'.png';}
};
Which throws an exception when I try to create an object:
t=new mapTile(1,1)
TypeError: Cannot set property 'visible' of undefined
in Chromium and fails silently in Firefox(with firebug)
This works OK though:
function mapTile(nx,ny)
{
//members
this.x = nx;
this.y = ny;
};
//methods
//this.prototype.xx=1;
mapTile.prototype.visible = function(){return true;};
What is the proper way to implement prototype methods inside the body?