Javascript expando objects

后端 未结 4 1838
醉梦人生
醉梦人生 2020-12-02 12:50

What are expando objects in javascripts?

For what purpose we need this ? Any complete example will be appreciated

I found 1 article here Javascript: The red

4条回答
  •  一个人的身影
    2020-12-02 13:41

    Everything except primitive types(string, number,boolean) are objects and support Key:values structure. properties(keys) can be accessed and set using the dot notation as well as the square brackets.

    var myObj = {};   
    myObj.myProp1 = 'value1'; //works, an expando property   
    myObj[myProp2] = 'value2'; // doesn't work, myProp2 is an undefined name.
    myObj['myProp2'] = 'value2'; // works  , an expando property   
    myObj[2010]= 'value'; //note the key is number, still works, an expando property??   
    myObj.2010 = 'value'; // FAILS. to use dot notation, key must be a string
    

提交回复
热议问题