prototypeの使用方法について論議がされている。
以前作成したサンプルにちょうど良いのがあったので、役に立つかどうかわからないが、もったいないので公開する。
時間がないため、詳細を省く事をご了承願いたい。
以前作成したサンプルにちょうど良いのがあったので、役に立つかどうかわからないが、もったいないので公開する。
時間がないため、詳細を省く事をご了承願いたい。
function Point(x,y){
this.x=x;
this.y=y;
}
var a=new Point(1,3);
alert(a.constructor==Point); //true(aのコンストラクタはPoint)
Point.prototype.swap
=function(){
var buf=this.x;
this.x=this.y;
this.y=buf;
}
var b=new Point(2,4);
alert(b.constructor==Point); //true(bのコンストラクタはPoint)
Point.prototype
={swap:
function(){
var buf=this.x;
this.x=this.y;
this.y=buf;
}
}
var c=new Point(3,5);
alert(c.constructor==Point); //false(cのコンストラクタはPointではない)
alert(c.constructor==Object); //true(cのコンストラクタはObject)
this.x=x;
this.y=y;
}
var a=new Point(1,3);
alert(a.constructor==Point); //true(aのコンストラクタはPoint)
Point.prototype.swap
=function(){
var buf=this.x;
this.x=this.y;
this.y=buf;
}
var b=new Point(2,4);
alert(b.constructor==Point); //true(bのコンストラクタはPoint)
Point.prototype
={swap:
function(){
var buf=this.x;
this.x=this.y;
this.y=buf;
}
}
var c=new Point(3,5);
alert(c.constructor==Point); //false(cのコンストラクタはPointではない)
alert(c.constructor==Object); //true(cのコンストラクタはObject)
誰かの役にたちますように...。