Object.prototype in JavaScript

后端 未结 2 621
遇见更好的自我
遇见更好的自我 2021-01-18 11:21

I have some JavaScript code that defines a function getElementsByAttribute as follows:

Object.prototype.getElementsByAttribute = function(attr)          


        
2条回答
  •  星月不相逢
    2021-01-18 11:52

    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.

提交回复
热议问题