super , ( ). , :
Fruit.prototype.sayName = function(){
this.super.sayName.call(this);
console.log( 'I am the color ' + this.color );
}
var orange = new Fruit( 'apple', 'red' );
orange.sayName();
( orange.super.sayName.call( orange ); , , -OO-. , . - (, ), , .
super , , . , :
var Grape = function(variety) {
Fruit.call(this, "grape", "purple");
this.variety = variety;
};
Grape.prototype = Object.create(Fruit.prototype);
Grape.prototype.sayName = function() {
this.super.sayName.call(this);
console.log('I am a ' + this.variety + ' grape');
};
var concordGrape = new Grape("Concord");
concordGrape.sayName();
, this.super , :
this
Object.getPrototypeOf(this)
Object.getPrototypeOf(Object.getPrototypeOf(this))
, Grape.prototype.sayName this.super.sayName, Fruit.prototype.sayName, . Fruit.prototype.sayName this.super.sayName, , , .
super :
var Grape = function(variety) {
Fruit.call(this, "grape", "purple");
this.variety = variety;
this.super = Object.getPrototypeOf( Object.getPrototypeOf( this ) );
};
this , , .
, super , ( ). , , .