4
は、私が最初にこのようなクラスを定義した:Firefoxで静か定義Javascriptのクラスのプロトタイプメソッド
t=new mapTile(1,1)
TypeError: Cannot set property 'visible' of undefined
クロム中と失敗します。私は、オブジェクトを作成しようとすると例外をスロー
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';}
};
(放火魔で)これはOKかの作品:
function mapTile(nx,ny)
{
//members
this.x = nx;
this.y = ny;
};
//methods
//this.prototype.xx=1;
mapTile.prototype.visible = function(){return true;};
体内にプロトタイプメソッドを実装する適切な方法は何ですか?
私はそれほど好きではありませんでしたが、あなたはポイントがあります。 –