• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 3. Array() > Example: An Extensible switch Function

Example: An Extensible switch Function

One of the nice things about JavaScript is it is an object-oriented language. It's built around the concept of objects, which makes it very easy to extend the language and add capabilities, if you choose to do so. (I choose to do so.)

The switch statement of Chapter 11 is one of the statements I like. It allows me to compare an unknown value against a set of known values, and at the first match, execute a code block. This makes it a very powerful feature of the language. The only thing I don't like about it is the inability to add new known values to the set of known values it checks against. I would have to replace the function containing the switch statement with another function or edit the function's source code (see Chapter 2's example for details on this). Either way is a bit long for simply adding one more known value.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint