Javascript DOM: Setting custom DOM element properties

前端 未结 4 547
北荒
北荒 2020-12-05 18:35

Is it ok to set custom properties on DOM elements, and rely on them persisting?

For example, given

 
&l
4条回答
  •  無奈伤痛
    2020-12-05 18:47

    This is what the specs say about the internal property accessors:

    Host objects may implement these internal methods in any manner unless specified otherwise; for example, one possibility is that [[Get]] and [[Put]] for a particular host object indeed fetch and store property values but [[HasProperty]] always generates false.

    and

    Host objects may define additional constraints upon [[Put]] operations. If possible, host objects should not allow [[Put]] operations in situations where this definition of [[CanPut]] returns false.

    However, I think this is just theoretical, and in reality expandos work as expected.

提交回复
热议问题