Is there a spec that the id of elements should be made global variable?

前端 未结 5 2107
死守一世寂寞
死守一世寂寞 2020-11-22 05:34

If I have a

in Chrome then in javascript I can do a.stuff() (it\'s like as if a is a global variable).
5条回答
  •  一整个雨季
    2020-11-22 05:42

    The worst thing about using elements this way is that they could break at any time if a new API is introduced that has the same name in the global scope.

    For example, if you had this prior to the addition of the Performance API

    Then that piece of code would've stopped working now in recent browsers that implemented the Performance API as a global performance object was added.

提交回复
热议问题