Chapter 10. Bracket notation: flexible property names

 

This chapter covers

  • Square brackets as an alternative to dot notation
  • The use of square brackets to set and get properties
  • The flexibility of square bracket notation
  • How to build a working game in The Crypt

In chapter 3 you saw how to create objects with curly braces and get and set properties with dot notation. You’ve used objects to model players, places, planets, and posts as well as quizzes and calendar events. You’ve added functions as properties to make methods and passed your objects to and from functions as arguments and return values. Objects are the center of the JavaScript universe!

In this chapter you take a look at a new way of working with object properties that gives you more flexibility with the property names, lets you use variables as keys, and gives you the ability to generate new properties from data while programs are running.

We also bring part 1 of Get Programming with JavaScript to a close with a working version of The Crypt, finally giving players the chance to explore a map and collect treasure! Square bracket notation provides a better way for you to manage the links between locations in the game, create a web of Place objects, and add a touch of mystery to the adventure. Ooooo, mystery ...

10.1. Using square brackets instead of dots

Up until now you’ve used dot notation to set and get object properties.

10.2. The Crypt—enhancing exit excitement

 
 
 
 

10.3. The Crypt—let the games begin!

 
 
 

10.4. What’s next?

 
 
 

10.5. Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest