In Node.js (ver. 0.12.0 ) I have a class with method defined like this:
In ./constructor.js
:
function Pow() {}
Pow.prototype.wow = require("./wow/definition.js");
module.exports = Pow;
In ./wow/definition.js
:
var Pow = require("../constructor.js");
function wow() {
return new Pow();
}
module.exports = wow;
In ./index.js
:
var Pow = require("./constructor.js");
var pow = new Pow();
pow.wow();
The last line of ./index.js
throws the following error:
object is not a function
at Pow.wow(./wow/definition.js:5:10)
Running the same code in Google Chrome (ver. 45.0.2454.101 64-bit ), which also uses the V8 engine but not the CommonJS require system, does not result in an error:
function Pow() {}
Pow.prototype.wow = wow;
function wow() {
return new Pow();
}
var pow = new Pow();
pow.wow();
Can anyone tell me why, in Nodejs, require("./constructor.js")
returns a constructor in ./index.js
but a non-constructable object in ./wow/definition.js
?