I am trying to implement very simple inheritance for some custom classes in node. I am doing something like this:
function MyClass() { this.myFunction = function(){ //do something } } function MySubclass(){ this.myOtherFunction = function(){ //do something else } } util.inherits(MySubclass, MyClass) console.log(MySubclass.super_ === MyClass); // true var x = new MySubclass() console.log(x instanceof MyClass); // true x.myFunction()
And if I run this, I will get the error:
TypeError: Object #<MySubclass> has no method 'myFunction'
This exact template works great for inheriting from events. EventEmitter. Doesn't this just work for custom classes, or is there something I am missing?
source share