On Mar 21, 10:30 pm, Jarek Foksa <[email protected]> wrote:
> > Oh, and you don't have to take my word for it:
>
> > Kangax, "What’s wrong with extending the DOM", 5 April 2010
> >http://perfectionkills.com/whats-wrong-with-extending-the-dom/
>
> Very nice article and discussion beneath it, thanks for pointing this out.
>
> But I still think that extending Element.prototype would be the best
> option in my case as I will be using the code inside Cocoa/Webkit
> wrapper only.
>
> I now realize that it's really easy to have naming clash, especially
> on form elements, so I should probably keep all my extensions in
> separate namespace, e.g.:
>
> Element.prototype.ext = {}
> Element.prototype.ext.disabled = function() { blah; }
> Element.prototype.ext.hasClass = function() {blah; }
> Element.prototype.ext.isSVG = function() { blah; }

Using that strategy, if you call the method as
someElement.ext.hasClass() then within the function this will
reference ext, not the element.


> Alternatively, I could use certain naming convention, e.g.:
>
> Element.prototype._disabled = function() { blah; }

Underscore is probably not a good choice, for some it indicates a
private method (i.e. it says "don't call this from outside code").
Better to use some letters, say uX (for utility extensions maybe?).

Don't create a disabled method as there already is a disabled property
for a number of DOM elements. How is it better to write:

  if (el.uXdisabled())

than

  if (el.disabled)


To do this stuff robustly, you often need to use getters and setters,
so:

Element.prototype.uXgetDisabled = function() {...}
Element.prototype.uXsetDisabled = function(arg) {...}


> Element.prototype._hasClass = function() {blah; }
> Element.prototype._isSVG = function() { blah; }


I think a wrapper approach will be more robust and future proof.

--
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]

Reply via email to