Dynamic Access
Get to know how to access members dynamically.
We'll cover the following...
To access a field, a property, or a method, we use the dot notation in JavaScript much like in languages like Java, C#, and many other languages. However, we can also access a member of an instance using the []
operator; we’ll look at yet another alternative to this in Getting and Setting Properties.
Accessing instance members
Following are the rules to access instance members:
- Use the dot notation, like
sam.age
orsam.play()
, if you know the member name at code writing time. - If the