0

I have been read some information about javascript inheritance but i am not sure how to manage the following situation. Let's say i have an object A with the attribute 'b' and 'c'. Attribute 'b' is a class like this:

A.b=function(elements, tags) {
 this.elements = elements;
 this.tags = tags;
}
A.b.prototype.funct1 = function() { 
  alert('a');
}

I want attribute "c" to extends class "b" but to add some elements in constructor and define own functions.

A.c = function(elements,tags) {
  A.c.prototype = new A.b(elements,tags);
  this.var = null;
};

A.c.prototype.funct2 = function(){
 alert('funct2');
}

I am using Prototype js. Can you tell if is bad practice or there is an elegant way to do this.

Aurelio
  • 24,702
  • 9
  • 60
  • 63
OSOMAN
  • 47
  • 1
  • 7
  • Nothing you showed here is related to PrototypeJS. Doesn't seem to be relevant that you are using it? Also, there are *many* questions about inheritance in JS already + tutorials on the Internet. None of them helped? For example: [Introduction to Object-Oriented JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript) – Felix Kling Jun 05 '15 at 14:58
  • @aduch: Well, depends. Did you *read* the question? ("Inhereance in Prototype JS", "I am using prototype js."). OP might just have used the wrong tag for prototypejs, which coincidentally is the right tag for the problem. – Felix Kling Jun 05 '15 at 15:01
  • The question keeps mentioning the Prototype JS library, but it looks like it is asking about prototypal OO in JS. – Quentin Jun 05 '15 at 15:03
  • I specified PrototypeJs because i didn't want an answer like this "If you are using JS Node you should do like this" (this is an example) – OSOMAN Jun 05 '15 at 15:03
  • Someone has ported the Prototype JS library to Node — https://github.com/rixius/prototype.node.js — so requiring Prototype JS (which doesn't appear remotely relevant) doesn't exclude Node. – Quentin Jun 05 '15 at 15:04
  • 1
    I think the name of prototype JS is the only thing I dislike more in the language's ecosystem than the $ variable. – Quentin Jun 05 '15 at 15:05
  • @Quentin oky, i am sorry if i created confusion. – OSOMAN Jun 05 '15 at 15:10
  • 1
    Here is an answer I posted which does Class inheritance in PrototypeJS http://stackoverflow.com/a/15527223/341491 – Geek Num 88 Jun 09 '15 at 04:46

0 Answers0