On Mar 21, 5:17 am, Jarek Foksa <[email protected]> wrote: > I do a lot of operations on objects retrieved by querySelector() and > simillar DOM methods, so I thought it would be nice to extend the > built-in Element object with some useful methods and properties.
Don't do that. Do not mess with host objects, you do not know how they will deal with added properties. > So far I didn't have any problems when adding new methods to > prototypes, You must not have tried IE, it doesn't have any kind of accessible inheritance for DOM objects. > but the things are not so obvious to me when I'm trying to > add new properties. > > For example, I would like to add Element.prototype.disabled property > that would be set to true if the given element has class "disabled" > and to false otherwise. Do not do that, there are 6 HTML elements that already have a disabled property that returns a boolean value. [...] > Could you give me some hints what is the proper way to achieve may goal? Test for the class. Note that Prototype.js has a scheme where it adds methods and properties to Element.prototype in browsers that support it and for others, adds the same methods and properties to elements directly. Despite constant criticism, they have persisted with that strategy for years. However, they are finally about to ditch it. You could do worse than learn from their mistake. -- Rob -- 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]
