Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Question about best method of creating inheritance in javascript


  • From: javascript@xxxxxxxxxx (Amanda Birmingham)
  • Subject: [Javascript] Question about best method of creating inheritance in javascript
  • Date: Tue, 23 Apr 2002 10:08:45 -0600

Hello, List,
I'm new here, so please forgive any faux pas.  I've been gearing up to 
write a very large OO javascript program, and have therefore been 
investigating the different merits of possible ways of subclassing in 
Javascript (yeah, I know "class" is a bit of a misnomer, but you know what 
I mean :)

So far, I've seen these three methods:
* make superclass constructor a method of subclass and call it inside the 
subclass constructor (without the "new").  This takes the subclass object 
and extends its "this" with the superclass info.

* inside the subclass constructor, create a new instance of the superclass. 
Then extend it and return that extended superclass as the subclass instead 
of the the "this".

* assign a new superclass object to the prototype property of the subclass 
constructor function.

Question 1:  when you create an instance of a subclass that inherits some 
stuff, do all of these methods result in you *also* creating objects of all 
the classes it inherits from?

Question 2: If *so*, what is the advantage of the prototype method (which, 
as I understand it, is the real, *approved* way of doing inheritance in 
javascript), since it seems that using prototype has problems of blocking 
access to methods of the superclass that have the same name as objects of 
the subclass  (unless you use something like Kevin Lindsey's workaround) ?

Answers, advice, and/or descriptions of other methods I've overlooked would 
be gratefully welcomed.  Thanks,

Amanda Birmingham
Web Application Developer