Extending the DOM



I’ve recently read that extending the DOM on the whole is bad, because of reasons listed here and here. As I understand it, the main reasons against it are:

  • It doesn’t work very well/at all in IE
  • It is possible to run into conflict, such as if a framework uses Document.prototype.hide and a browser then implements a hide function on document elements
  • Browsers implement things in wildly different ways

However, I haven’t seen anyone ask these questions. 1) if I wanted to extend the DOM, how would I do it safely? Besides the obvious use of a wrapper, how would I natively add a function, such as hide to the DOM as a whole, safely? And, 2) If it’s not possible to implement it safely, what are the specific reasons? Can I implement checks, such as checking typeof Document.prototype.hide == 'undefined' before implementing my own function on the prototype?

In other words, explain to me how I can extend the DOM safely and what I could do to make sure that if a browser were to make the hide function, what I could do to not make my code have to be completely reworked.

newest questions tagged javascript – Stack Overflow