Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  112] [ 4]  / answers: 1 / hits: 23236  / 14 Years ago, wed, march 24, 2010, 12:00:00

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-headed stepchild of web development


More From » expando

 Answers
15

Well, in javascript, any object is an expando object. What it means is, as the article covers, that whenever you try to access a property1 it will automatically be created.



var myObj = {}; // completely empty object
myObj.myProp = 'value';


The moment you assign myProp a value, the property myProp is dynamically created, eventhough it didn't exist before. In a lot of other languages, such as C#, this is not normally possible (actually C# has just enabled expando object support as well, but that's besides the point). To access a property in a normal class in C#, you need to specify in the class that it does indeed have this property.



1 Not quite correct. See npup's comment below for clarification.


[#97258] Saturday, March 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeniferjaliyahf

Total Points: 650
Total Questions: 104
Total Answers: 86

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
;