Skip to content Skip to sidebar Skip to footer

Object.prototype In JavaScript

I have some JavaScript code that defines a function getElementsByAttribute as follows: Object.prototype.getElementsByAttribute = function(attr) { var children = this.all || thi

Solution 1:

IE DOM elements aren't normal Javascript objects and do not inherit prototypes as you would expect.

http://perfectionkills.com/whats-wrong-with-extending-the-dom/


Solution 2:

Adding things to Object.prototype is a really bad idea. It will be added to every object, and that will cause unintended behavior, I guarantee it.

Simply define your function and decorate it onto whatever objects you need dynamically.


Post a Comment for "Object.prototype In JavaScript"