0

There javascript class, if he can 'inherit' a few objects - that is, to know their methods

var A = function  (a,c){};

var N = {  
     properties1: function(){};
};

var M1 = {
     properties2: function(){};
};
var M2 = {
     properties3: function(){};
};

How to do that would 'A' , knew (the heir) of 'N' and 'M1' , 'M2' ...'M10' ... ?

A.prototype = N;
A.prototype = M1;
A.prototype = M2;

It does not work :( How to implement such an event structure in javascript

4
  • 2
    Multiple inheritance is not supported in JS. Commented Feb 21, 2014 at 8:06
  • Can it be like that circumvent or emulate?If you need a structure described above ? Commented Feb 21, 2014 at 8:12
  • Take a look at mixins. Commented Feb 21, 2014 at 8:20
  • I wonder why you even expect assigning to A.prototyep multiple times to work. If I have this code: var a = 1; a = 2; a = 3;, then in the end, a will have the value 3, not 1, 2, 3 (somehow). Commented Feb 21, 2014 at 9:17

1 Answer 1

1

Javascript has prototypical model/inheritance. Please use it and avoid writing Java/C++ in Javascript. It's a different model.

EDIT:

In my opinnion if you need such a thing - you're doing it wrong :). And I very much recommend to read this SO answer about prototypes.

Sign up to request clarification or add additional context in comments.

2 Comments

How does this answer the question?
A.prototype = N; A.prototype = M1 === replaced by === A.prototype.properties1 = N.properties1; A.prototype.properties2 = M1.properties2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.