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

Dan Costea costea.dan at ssi-schaefer.ro
Wed Apr 24 12:18:57 CDT 2002


I recommend you to read the chapter "Working with Objects" of "Client-Side
JavaScript Guide" book:
http://developer.netscape.com/docs/manuals/js/client/jsguide/obj.htm

Dan.


----- Original Message -----
From: "Amanda Birmingham" <lists at imladris.com>
To: <javascript at LaTech.edu>
Sent: Tuesday, April 23, 2002 9:08 AM
Subject: [Javascript] Question about best method of creating inheritance in
javascript


> 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
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list