I have written stuff in other languages where you inherit a class, and the super class constructor is called when and object is created of the subclass. However, in the pattern I find all over for inheritance from javascript, the super constructor is actually run when inheritance is established.
Example:
var thingy = function(){ this.constructionTime = new Date() };
var thing2 = function(){ this.type="thing2" };
thing2.prototype = new thingy();//thingy constructor actually runs here
var t2 = new thing2();//does NOT call thingy constructor
setTimeout(function(){
var t3 = new thing2();
t3.constructionTime == t2.constructionTime; // TRUE
},100);
Then I found a few, much less common, examples where they did something like this:
var athing = function(){
this.constructionDate = new Date();
}
athing.prototype.showDate = function(){ console.log(this.constructionDate) };
var something = function(){
athing.apply(this);
this.note = "I'm something";
}
var x = new something();
then calling x = new something() does run the constructor, but does not inherit methods. So I add
something.prototype = athing.prototype;
which does not give x the methods, but new objects
y = new something();
y.showDate();//shows the date generated during its construction
do have them.
So here's my perhaps overly broad question(s): am I missing something? Is there a reason NOT to use this pattern other than wanting your super constructor to only be run once?