Why does the following code work only under Node.js 5.x and 6.x, but breaks in 4.x and earlier versions?
Is there a way to modify it in such a way to make work in any Node.js 0.10.x - 6.x?
'use strict';
var util = require('util');
function Parent() {
}
Parent.prototype.show = function () {
return this.msg(); // virtual-like call;
};
function Child() {
}
Child.prototype.msg = function () {
return 'Hello!';
};
util.inherits(Child, Parent);
var test = new Child();
console.log(test.show());
In Node.js 5.x and 6.x it displays Hello!. And in any earlier version of Node.js it displays TypeError: this.msg is not a function.