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

Chapter 23. Cookies and Creating Your Ow... > Adding Properties to Existing Object...

Adding Properties to Existing Objects

You also can add properties to existing objects in JavaScript, just by assigning such properties values as if those properties existed. To do this, the object you’re working with must be a real object, which means you must create it with the new operator.

Here’s an example. In this case, I’ll create a new string with a greeting in it, add a new property named purpose to the string, and set the string’s purpose to "greeting":


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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