What's wrong with adding properties to DOM Element objects?

前端 未结 3 1357
情书的邮戳
情书的邮戳 2020-12-01 07:51

I\'ve been looking for a straight answer for this (I can think of lots of possiblities, but I\'d like to know the true reason):

jQuery provides a .data() method for

3条回答
  •  抹茶落季
    2020-12-01 08:23

    I think you can add all the properties you want, as long as you only have to use them yourself and the property is not a method or some object containing methods. What's wrong with that is that methods can create memory leaks in browsers. Especially when you use closures in such methods, the browser may not be able to complete garbage cleaning which causing scattered peaces of memory to stay occupied.

    This link explains it nicely.

    here you'll find a description of several common memory leak patterns

提交回复
热议问题