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

Ankur Aggarwal
  • 2,993
  • 5
  • 30
  • 56
R__
  • 33
  • 4
  • 2
    Multiple inheritance is not supported in JS. – raina77ow Feb 21 '14 at 08:06
  • Can it be like that circumvent or emulate?If you need a structure described above ? – R__ Feb 21 '14 at 08:12
  • Take a look at [mixins](http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/). – raina77ow Feb 21 '14 at 08: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). – Felix Kling Feb 21 '14 at 09:17

1 Answers1

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.

Community
  • 1
  • 1
lukas.pukenis
  • 13,057
  • 12
  • 47
  • 81