Modify prototypes of every possible DOM element

后端 未结 2 2073
故里飘歌
故里飘歌 2020-12-11 21:59

Updated title to better reflect what I\'m trying to do.

In short, there are different constructors for different dom elements, and they don\'t seem to all share a co

2条回答
  •  生来不讨喜
    2020-12-11 22:17

    I think what you want can be achieved by prototyping the Element interface, like

    Element.prototype.getElementsByClassName = function() {
        /* do some magic stuff */
    };
    

    but don't do this. It doesn't work reliably in all major browsers.

    What you're doing in the example in your question is not advisable, too. You're actually extending host objects. Again, please don't do this.

    You'll fall in exactly those pitfalls Prototype ran into.

    I don't want to merely copy Kangax' article, so please read What’s wrong with extending the DOM.

    Why do you want this in the first place? What's your goal?

提交回复
热议问题