[javascript]
//コンストラクタクラス定義、インスタンス生成、プロトタイプ継承を使った関数を参照
var Menber = function(fname,sname){
this.fname = fname;
this.sname = sname;
};
Menber.prototype.me1 = function(){
return this.fname + this.sname;
}
Menber.prototype.me2 = function(){
return this.fname + this.sname;
}
var men1 = new Menber('morita','kenji');
var men2 = new Menber('kenji','kenji');
// オブジェクトリテラルでのprototype定義
var Menber = function(fname,sname){
this.fname = fname;
this.sname = sname;
}
Menber.prototype = {
add : function(){return this.fname + this.sname},
add2 : function(){return this.sname + this.fname}
};
var men1 = new Menber('ff','ee');
console.log(men1.add(),men1.add2());
// プロトタイプチェーン
var Animal = function(){};
Animal.prototype = {
walk : function(){document.write('tokotoko');}
}
var Dog = function(){};
Dog.prototype = new Animal();
Dog.prototype.bark = function(){document.write('baubau');}
var d = new Dog();
d.walk();
d.bark();
[/javascript]