Should I use an empty property key?

前端 未结 5 759
名媛妹妹
名媛妹妹 2020-12-13 08:18

I\'ve tested this only in Firefox, but apparently you can use an empty string as a key to a property in an object. For example, see the first property here:

         


        
5条回答
  •  庸人自扰
    2020-12-13 08:51

    I think it's ok. "" has semantics in your application, and its valid javascript. So have at it.

    Note that

    x."" = 2;

    will error out, so you need to use syntax like

    x[""] = 2;

提交回复
热议问题