Subj : Re: Implementing inheritence? To : netscape.public.mozilla.jseng From : Brian Genisio Date : Thu Jan 29 2004 08:40 am Brendan Eich wrote: > Brian Genisio wrote: > >> Hi all, >> >> Is there a way in spidermonkey to have an object inherit all of a >> parent's properties and methods? > > > > JS is all about delegation, not inheritance -- but the two look the same > from many angles. If the first object O's prototype (__proto__ property > in SpiderMonkey) refers to the second, P (the "parent"), then for any > property X in P, O.X or O["X"] will access P.X or P["X"], unless there > is a direct property of O named X (in which case O.X is said to "shadow" > P.X). > >> Using the DOM as an example, class Document inherits from class Node. >> Can I tell spidermonkey that this is the case, or do I have to >> implement it myself. It looks pretty easy for me to do it myself, but >> I thought I would check if there is an easy way. I couldnt find any. > > > > If you are implementing the DOM, you might want to look at Mozilla's DOM > implementation. > > /be Ahhhh... So that is what the prototype is for! Great. That makes my life so much easier. I was implementing what the prototype gives me, by registering my class with the prototype's methods and props, and then defaulting to the prototypes's get and set methods if I didnt match anything. I got the same effect using the prototype, but it was a _lot_ messier. Thanks for the help. There are a lot of details, such as this, that I am not finding clear explanation for directly in the document. This newsgroup has been _GREAT_ at explaining the things that I have not found clear in the docs. Thanks a bundle, Brian .