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)?
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)? I apologize for the question - I'm just seeing either the DOM side of Javascript or the OO side and it doesn't seem like I've read how it is all pulled together. Thanks On Jun 13, 3:29 am, Peter van der Zee <[email protected]> wrote: > On Mon, Jun 13, 2011 at 5:44 AM, radiate <[email protected]> wrote: > > Not sure if I misunderstood the purpose the prototype object of a > > javascript object but I wanted to add functionality to an HTML Table > > Cell that would generate a text box if a user clicked on the cell. I > > wanted to provide this functionality to all table cells in the table. > > I thought this would be a good use of the prototype functionality in > > Javascript. It seems like I can't get it to work. Here's the code: > > Well, there are two reasons it's not really working or going to work like > that. > > For one, in order to extend an object through prototype you have to > extend the parent object's prototype property, not that of the child. > So.. if person is a child of Person: > > person.prototype.newMethod = function(){}; // NOT > Person.prototype.newMethod = function(){}; // YES > > Note that the .prototype property of an instance (person) does not > refer to "its prototype object", or Person.prototype. Formally you > have no access to it through an instance but in most (not all!) > browsers you can still find it through .__proto__ . > > The other reason results might vary is because dom nodes are > implemented using so called "host objects". These are special kinds of > objects that typically don't adhere to the general rules of js. That > means that in most cases, they behave as regular objects insofar as > accessing properties go (and not even that, really) but extending them > or creating new instances of them is all left up to the > implementation. Pretty much any object related to the DOM is a host > 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]
