2

How to add multiple interface on the same class in javascript.

Adding 1 interface works fine with this :

Myclass.prototype = Object.create(Interface1.prototype);

Like this, I can implement methods which are declare from "Interface1" in my class "Myclass". But I would like to do this twice with another Interface like this :

Myclass.prototype = Object.create(Interface1.prototype);
Myclass.prototype = Object.create(Interface2.prototype);

But I get only the method from "Interface2", and not "Interface1". How can I Have the 2 Interfaces. I read some things about mixin and extend prototype but I don't know how to use this.

  • You likely need to bear mind that javascript doesn't have *true* interfaces, this is just a [pattern](http://stackoverflow.com/questions/13041168/a-running-example-or-working-demo-of-interface-pattern-in-javascript) of **objects** that you're calling interfaces. So this can be thought of as [Multiple inheritance/prototypes in JavaScript](http://stackoverflow.com/questions/9163341/multiple-inheritance-prototypes-in-javascript) – Liam Jul 24 '15 at 09:11
  • Thanks for your reply, I will check your links ! – Thibaultblf Jul 24 '15 at 12:13

0 Answers0