开发者

setting property of js map/object

开发者 https://www.devze.com 2023-02-17 09:03 出处:网络
Can i use myWidget.errorLableMap.key =\"errormsg\"; insted of following to set property of a js object/map.

Can i use

myWidget.errorLableMap.key ="errormsg";  

insted of following to set property of a js object/map.

myWidget.errorLableMap["key"] ="errormsg";
开发者_StackOverflow社区


You can do both - they are equal ways of assigning a property value. The difference is - using [] you can work with properties that are not valid variable names in javascript, e.g. you can do:

myWidget.errorLableMap["key 1"] = "something"

but obviously following will not work:

myWidget.errorLableMap.key 1 = "something"
0

精彩评论

暂无评论...
验证码 换一张
取 消