myObject.prototype.__proto__ = parentObject.prototype;
This will basically copy the prototype of the parent object into the child… Very simple – This method of achieving inheritance is fine provided that the engine which will run the code supports the prototype.__proto__ property (As does the Node.js V8 engine). In cases where __proto__ is not supported, an alternative which is often used is:
myObject.prototype = new parentObject();
This basically does the same thing, it’s making the prototype of the current object be an instance of a chosen parentObject.
… Ok so that seems to take care of it. Right?
But… How to deal with constructor arguments, multiple inheritance, method overloading…? There are tricks and patterns that you can follow to avoid having to use any of these things, but these patterns can often harm your code quality more than help it.
In the context of nmix, a mixin is a special (instantiable) function which is a combination of other (instantiable) functions (which have been mixed into it). Basically it lets you define a class which is a mixup of a bunch of other classes. Some benefits of using nmix is that you can pass constructor arguments to any parent ‘class’ and you can overload methods in a way such that you can still call the base methods when needed. For more details, please check out the examples on the nmix npm page: https://npmjs.org/package/nmix