definiert ich eine Klasse wie folgt zunächst:Definieren von Javascript-Klasse Prototyp Methoden
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';}
};
, die eine Ausnahme auslöst, wenn ich versuche, ein Objekt zu erstellen:
t=new mapTile(1,1)
TypeError: Cannot set property 'visible' of undefined
in Chrom und nicht still in Firefox (mit Firebug)
Dies funktioniert OK aber:
function mapTile(nx,ny)
{
//members
this.x = nx;
this.y = ny;
};
//methods
//this.prototype.xx=1;
mapTile.prototype.visible = function(){return true;};
Was ist der richtige Weg, um prototypische Methoden im Körper zu implementieren?
Nun, ich mochte es nicht viel, aber Sie haben einen Punkt. –