Dynamic Access
Explore dynamic access to object fields and methods in JavaScript by using dot and bracket notation, Object.keys, and prototype inspections. Understand how to query and iterate members at runtime to effectively apply metaprogramming concepts similar to reflection in other languages.
We'll cover the following...
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.ageorsam.play(), if you know the member name at code writing time. - If the