Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Commonmark migration
Source Link

##The Best Approach ... (I've seen)

The Best Approach ... (I've seen)

This is a good starting point -- we use the combination of Constructor-Stealing & Prototypical-Inheritance (noted by #ppoliani above):

function SuperType() {
 this.super = 'type';
}
SuperType.prototype = { m: function () { } };
function C() {
 SuperType.call(this);
 this.key = 'value';
};
C.prototype = (new (function () {
 $.extend(this, new SuperType());
 this.some = 'thing';
})());
var c = new C();
console.log(c);

However, this could use some tuning up -- for instance, the C.prototype object (uses new so that we can use this -- which is good) extends this with new SuperType() and the method is added to this and not C.prototype -- not good. It also uses a non-native $.extend function -- not good.

Of course, the heavy use of inheritance can be a very undesirable methodology. Complex-Deep-Inheritance-Hierarchies often lead to extreme entropy in your Class Architecture. If your hierarchies are complex, deep architectures become maintenance, portability, and adaptivity nightmares. If this is the case, begin implementing The Decorator Pattern.

This is rather a demonstrative answer here to give readers better tools for manipulating the inheritance chain.

Hope this helps.

##The Best Approach ... (I've seen)

This is a good starting point -- we use the combination of Constructor-Stealing & Prototypical-Inheritance (noted by #ppoliani above):

function SuperType() {
 this.super = 'type';
}
SuperType.prototype = { m: function () { } };
function C() {
 SuperType.call(this);
 this.key = 'value';
};
C.prototype = (new (function () {
 $.extend(this, new SuperType());
 this.some = 'thing';
})());
var c = new C();
console.log(c);

However, this could use some tuning up -- for instance, the C.prototype object (uses new so that we can use this -- which is good) extends this with new SuperType() and the method is added to this and not C.prototype -- not good. It also uses a non-native $.extend function -- not good.

Of course, the heavy use of inheritance can be a very undesirable methodology. Complex-Deep-Inheritance-Hierarchies often lead to extreme entropy in your Class Architecture. If your hierarchies are complex, deep architectures become maintenance, portability, and adaptivity nightmares. If this is the case, begin implementing The Decorator Pattern.

This is rather a demonstrative answer here to give readers better tools for manipulating the inheritance chain.

Hope this helps.

The Best Approach ... (I've seen)

This is a good starting point -- we use the combination of Constructor-Stealing & Prototypical-Inheritance (noted by #ppoliani above):

function SuperType() {
 this.super = 'type';
}
SuperType.prototype = { m: function () { } };
function C() {
 SuperType.call(this);
 this.key = 'value';
};
C.prototype = (new (function () {
 $.extend(this, new SuperType());
 this.some = 'thing';
})());
var c = new C();
console.log(c);

However, this could use some tuning up -- for instance, the C.prototype object (uses new so that we can use this -- which is good) extends this with new SuperType() and the method is added to this and not C.prototype -- not good. It also uses a non-native $.extend function -- not good.

Of course, the heavy use of inheritance can be a very undesirable methodology. Complex-Deep-Inheritance-Hierarchies often lead to extreme entropy in your Class Architecture. If your hierarchies are complex, deep architectures become maintenance, portability, and adaptivity nightmares. If this is the case, begin implementing The Decorator Pattern.

This is rather a demonstrative answer here to give readers better tools for manipulating the inheritance chain.

Hope this helps.

Source Link
Cody
  • 10.1k
  • 4
  • 65
  • 48

##The Best Approach ... (I've seen)

This is a good starting point -- we use the combination of Constructor-Stealing & Prototypical-Inheritance (noted by #ppoliani above):

function SuperType() {
 this.super = 'type';
}
SuperType.prototype = { m: function () { } };
function C() {
 SuperType.call(this);
 this.key = 'value';
};
C.prototype = (new (function () {
 $.extend(this, new SuperType());
 this.some = 'thing';
})());
var c = new C();
console.log(c);

However, this could use some tuning up -- for instance, the C.prototype object (uses new so that we can use this -- which is good) extends this with new SuperType() and the method is added to this and not C.prototype -- not good. It also uses a non-native $.extend function -- not good.

Of course, the heavy use of inheritance can be a very undesirable methodology. Complex-Deep-Inheritance-Hierarchies often lead to extreme entropy in your Class Architecture. If your hierarchies are complex, deep architectures become maintenance, portability, and adaptivity nightmares. If this is the case, begin implementing The Decorator Pattern.

This is rather a demonstrative answer here to give readers better tools for manipulating the inheritance chain.

Hope this helps.

lang-js

AltStyle によって変換されたページ (->オリジナル) /