Javascript and inheritance, gotcha...
I ran into one little issue when using the built in inheritance helper from node.
I created a "class" with some methods, this class should inherit from EventEmitter. Naturally I did this:
var util = require('util'); var EventEmitter = require('events').EventEmitter; function myClass() { EventEmitter.call(this); } myClass.prototype.mySetter = function() {}; util.inherits(myClass, EventEmitter);
When I was using an instance of this very class, the setter function was gone. This was very odd and it took me quite a time until I realized that the inherits helper overwrites the prototype of my ChildClass. (Which became obvious when I was looking at the source: https://github.com/joyent/node/blob/master/lib/util.js#L557 )
So, the right way to do the inheritance was simply moving the inherits line up:
var util = require('util'); var EventEmitter = require('events').EventEmitter; function myClass() { EventEmitter.call(this); } util.inherits(myClass, EventEmitter); myClass.prototype.mySetter = function() {};
That's it....











