Answer the question
In order to leave comments, you need to log in
How to Design a Hierarchy of Object Constructors in JavaScript
Hello. The question is about server-side JavaScript, although this is not essential. I have no experience in writing serious applications in JS, the other day I ran into a problem - how to organize the inheritance hierarchy. I am writing a small TCP server for now, which I will expand, so inheritance has become lumpy.
Who has experience? Any patterns?
I tried to use a factory, but it doesn't work to inherit methods -> pastebin.com/Nn7TymAN
How can I implement this?
Is it possible to make inheritance of encapsulated methods?
Answer the question
In order to leave comments, you need to log in
And if you mix coffee with js - you won’t get confused - there will be spaghetti at the output :) If you didn’t find what you were looking for in this collection, I doubt that you will find it at all.
1. Use CoffeeScript because it's more convenient.
2. OOP in Javascript: Inheritance
What prevents you from calling the parent constructor by class name?
var Parent=function(){
this.par='par';};
Parent.prototype.parProto='parProto';
var Child=function(){
Parent.apply(this);
this.chld='chld';};
Child.prototype=Object.create(Parent.prototype);
Child.prototype.chldProto='chldProto';
var Current=function(){
Child.apply(this);}
Current.prototype=Object.create(Child.prototype);
var inst=new Current;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question