javascript - Augmenting the prototype of DOM element nodes? -
i know how add new methods every object - augmenting object's prototype:
object.prototype.foo = function() { };
but, possible define new methods dom element nodes only? dom element node objects have prototype? or there maybe prototype dom nodes in general?
or prototype objects exist built-in objects?
yes, not in browsers. internet explorer 8 supports dom prototypes (to extent), firefox, chrome, opera , safari.
htmlelement.prototype.toggle = function () { this.style.display = this.style.display == 'none' ? '' : 'none'; }
many consider bad practice extend dom objects via prototype. kangax has great article on subject: http://perfectionkills.com/whats-wrong-with-extending-the-dom/. however, dom prototypes allow implement standards-based methods in environments don't support them yet, shims ecmascript 5th edition methods.
Comments
Post a Comment