In a javascript class, I defined an attribute which is of object type and set an empty object({} or new object()) as the initial value. The problem arose that every item seems to have the exact same value of this attribute. This made me alarmed at the possibility of using the identical empty object created initially. I tested and the result confirmed my hypothesis. The solution is to initialize this attribute later in a lazy fashion. That is to judge whether it is null and initialize it in a method, rather than define directly in the attribute line like java.
a hard-to-discover problem caused by the empty javascript object
最新推荐文章于 2019-10-26 09:39:21 发布