D
D
Dennis Leukhin2012-09-20 16:02:56
JavaScript
Dennis Leukhin, 2012-09-20 16:02:56

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

3 answer(s)
D
Denis Pushkarev, 2012-09-20
@stonedmind

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.

A
avalak, 2012-09-20
@avalak

1. Use CoffeeScript because it's more convenient.
2. OOP in Javascript: Inheritance

D
Denis Pushkarev, 2012-09-20
@rock

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;

Bicycle collection

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question