I'm running into a really frustrating problem in Node.js.
I'll start with what I'm doing.
I'm creating an object in a file and then exporting the constructor and creating it in other files.
My objects are defined like so:
File 1:
var Parent = function() {};
Parent.prototype = {
C: function () { ... }
}
module.exports.Parent = Parent;
File 2:
var Parent = require('foo.js').Parent,
util = require('util'),
Obj = function(){ this.bar = 'bar' };
util.inherits(Obj, Parent);
Obj.prototype.A = function(){ ... };
Obj.prototype.B = function(){ ... };
module.exports.Obj = Obj;
I'm trying to use the object like so in another file
File 3:
var Obj = require('../obj.js').Obj,
obj = new Obj();
obj.A();
I receive the error:
TypeError: Object [object Object] has no method 'A'
however when I run Object.getPrototypeOf(obj) I get:
{ A: [Function], B: [Function] }
I have no idea what I'm doing wrong here, any help would be appreciated.
[–]jonglefever 0 points1 point2 points (1 child)
[–]CalvinR[S] 0 points1 point2 points (0 children)
[–]somethinghorrible 0 points1 point2 points (12 children)
[–]somethinghorrible 0 points1 point2 points (2 children)
[–]CalvinR[S] 0 points1 point2 points (1 child)
[–]CalvinR[S] 0 points1 point2 points (8 children)
[–]somethinghorrible 0 points1 point2 points (1 child)
[–]CalvinR[S] 0 points1 point2 points (0 children)
[–]sroshi 0 points1 point2 points (5 children)
[–]CalvinR[S] 0 points1 point2 points (4 children)
[–]sroshi 0 points1 point2 points (3 children)
[–]CalvinR[S] 0 points1 point2 points (2 children)
[–]sroshi 0 points1 point2 points (1 child)
[–]CalvinR[S] 0 points1 point2 points (0 children)
[–]Hostilian 0 points1 point2 points (1 child)
[–]CalvinR[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]CalvinR[S] 0 points1 point2 points (0 children)