I have the following example:
// MyType.js
function MyType(){}
MyType.prototype.getFile = function(){
return __filename;
}
// SubType.js
var util = require('util');
function SubType(){}
util.inherits(SubType, MyType);
// test.js
var assert = require('assert'),
subtype = require('./SubType'),
myObject = new subtype();
assert.equal(myObject.getFile(), '/some/path/SubType.js'); // currently it fails, obviously
I know __filename doesn't work that way, but I was hoping there's a alternate late binding version of __filename or something equivalent?
Does the following code return the correct fileName?
function MyType(){
this.__fileName=__filename;
//maybe some other code you want to re use in subtype(s)
}
MyType.prototype.getFile = function(){
return this.fileName;
}
One thing I'm not sure of when you re use parent constructor if the fileName is still correct:
function SubType(){
MyType.call(this);
}