Java Reference
In-Depth Information
flash: { realName: "Barry Allen" },
greenLantern: { realName: "Hal Jordan" },
martianManhunter: { realName: "John Jones" }
}
The values in nested objects can be accessed by referencing each property name in order
using either dot or bracket notation:
jla.wonderWoman.realName
<< "Diana Prince"
jla['flash']['realName']
<< "Barry Allen"
You can even mix the different notations:
jla.martianManhunter['realName']
<< "John Jones"
Objects as Parameters to Functions
An object literal can be passed as a parameter to a function. This allows the arguments to
be given in any order and for default values to be used.
The following example shows how this can be done:
function greet (options) {
options = options || {};
greeting = options.greeting || "Hello";
name = options.name || "Anon";
age = options.age || 18
return greeting + "! My name is " + name + " and I am "
+ age +
" years old.";
}
Search WWH ::




Custom Search