prototype
は、クラスを定義する必要があるとprototype
を使用して継承を設定し、クラスではなく、JavaScriptでのオブジェクトに定義された参照オブジェクトです:
var animal = {eats:true};
function Rabit(){};
Rabit.prototype = animal;
Rabit.prototype.jumps = true;
var rabit = new Rabit();
rabit.jumps; // true
rabit.eats; // true
それとも、より良いあなたが定義した場合クラスと両方のエンティティ:
function Animal(){};
Animal.prototype.eats = true;
function Rabit(){};
Rabit.prototype = new Animal();
Rabit.prototype.jumps = true;
var rabit = new Rabit();
rabit.jumps; // true
rabit.eats; // true
のGeckoブラウザで文書化されていない__proto__
オブジェクトはlatesあなたはプロトタイプチェーンをだます静的オブジェを継承することを、Googleのクロムのような、あります他からのct:
var animal = {eats:true};
var rabbit = {jumps:true};
rabbit.__proto__ = animal;
rabit.jumps; // true
rabit.eats; // true
ちょっとありがとうございます。:)\ –
あなたの質問に対する回答であれば、答えをマークしてください –