I have a base class:
Stage.js:
function Stage(name) {
this.my_name = name;
}
Stage.prototype.name = function() {
return this.my_name;
}
module.exports = Stage;
Parallel:
var Stage = require("./Stage");
ParallelStage.prototype = Stage.prototype;
ParallelStage.prototype.execute = function() {
console.log("+++ Executing stage " + this.name()+ " in parallel...");
return this;
}
function ParallelStage(name) {
Stage.call(this,name);
return this;
}
module.exports = ParallelStage;
and Serial.js:
var Stage = require("./Stage");
SerialStage.prototype = Stage.prototype;
SerialStage.prototype.execute = function() {
console.log("+++ Executing stage " + this.name()+ " in serial...");
return this;
}
function SerialStage(name) {
Stage.call(this,name);
return this;
}
module.exports = SerialStage;
However, when I run:
var Parallel = require ("./ParallelStage");
var Serial = require ("./SerialStage");
var parallel = new Parallel("Extraction");
parallel.execute();
I get the following output:
+++ Executing stage Extraction in serial...
I am clearly missing something fundamental in the inheritance of javascript and prototype. Can someone tell me what I'm missing here? I expected it to show the execution of the scene in parallel, and not serial ...
source
share