Answer the question
In order to leave comments, you need to log in
Inheritance in JS Is it better to use mixins?
There is a fairly large project on node js. Stateful app. At the start, I load data from Mongo and create my own classes based on them. They all inherit from a "main class" that contains most of the methods used and the persistence logic in Mongo. Many classes also inherit from other classes.
Inheritance is implemented like this:
MyClass.prototype = _.extend(Object.create(CommonClass.prototype),SpecialClass.prototype,...);
var Ob = function(opts){
this.attr1 = opts.attr1;
.....
}
Ob.prototype.attr25 = 500;
Ob.prototype.method1 = function(){
//расчет расстояния между двумя точками, координаты заложены в атрибутах, некоторые лежат в прототипе (attr25)
var distance = Math.sqrt(...)
return distance < 1000;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question