On Mon, Jun 13, 2011 at 12:43 PM, radiate <[email protected]> wrote: > Hi Peter, > > Thanks for your response. For clarification purposes, it sounds like > you are saying I extended the child, which in this case was pick. Are > you saying that if I were to "fix" this I would've extended the HTML > element that pick was derived from (the parent)?
Yes. That's how you "extend" objects through prototype (in js); through the parent. Whenever you add a method to that prototype, all of its instances will also have that method (unless overridden). > > Also, it sounds like from your last paragraph that extending DOM > Elements is not typical practice. So (and please excuse my > terminology), OOP in Javascript is really about data-handling/data- > processing for the most part. Once the data is derived as desired it > then is outputted using built-in DOM functions (eg. appendChild, > innerHTML, etc)? No, not exactly. When you created the object, it's perfectly fine. But objects that are created in the DOM, like html objects, are called "host objects". Because they are created and governed by the host and not by you. The rules for these host objects can differ from what's normal in js. So you should do it with your own objects and stay away from these host objects. That means no extending HTMLDOMElement or whatever these super constructors are called. Also, OOP in js is not "about anything"... it's just a tool in the language. And everything in js is an object, so the name is kind of confusing anyways :) Just use prototype to create an architecture or make stuff easier for yourself. Stay away from DOM elements or the global Object object. - peter -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
