Java Reference
In-Depth Information
superman["real" + " " + "name"] // the property is built
using
string concatenation
<< "Clarke Kent"
If you try to access a property that doesn't exist, undefined will be returned:
superman.city
<< undefined
Calling Methods
To call an object's method we can also use dot or bracket notation. Calling a method is the
same as invoking a function, so parentheses need to be placed after the method name:
superman.fly()
<< "Up, up and away!"
superman['fly']()
<< "Up, up and away!"
Checking if Properties or Methods Exist
The in operator can be used to check whether an object has a particular property. So, for
example, we can check if the superman object has a property called city using this
code:
"city" in superman
<< false
Alternatively, you could also check to see if the property or method doesn't return un-
defined :
superman.city !== undefined
<< false
Search WWH ::




Custom Search