5
In "prototypes" I have used several times the Element.prototype
and the HTMLElement.prototype
. I wanted to know what is each and what is the difference between them in example, if possible. Because in some tests, like these, I had the same result:
HTMLElement.prototype.tooltip(); // funciona com um elemento normalmente
Element.prototype.tooltip(); // funciona com o mesmo elemento normalmente
Could someone show me the practical difference between the two, if not some concept or specification.
Another question that is while the NodeList.prototype
, I know until the moment I can use it to, for example, the document.querySelectorAll('elemento')
. But I guess I’d have to wear one forEach
and apply a prototype
already existing, thus:
HTMLElement.prototype.tooltip = function(){
...
}
NodeList.prototype.tooltip = function(){
[].forEach.call(NodeList, function(el){ // O NodeList dessa Linha, como usá-lo?
el.tooltip() // tooltip já criado para elementos em particulares
})
}
In the forEach
I’m trying to use the NodeList
as an Array, could also use the Array.from()
, but what I pass as parameter instead of "Nodelist", the this
doesn’t work...
Thank you in advance.
You already have the answer, I just wanted to point out that generally extending this type of prototype is not recommended, due to the particularities of its implementation and the possibility of collisions with properties that can be added to the specification in the future. http://perfectionkills.com/whats-wrong-with-extending-the-dom/.
– bfavaretto
@bfavaretto, I just started reading because I’m a little busy... but already taking a general superfial look, I found it very interesting.
– Samir Braga