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

Chapter 23. Cookies and Creating Your Ow... > Adding Methods to Existing Objects

Adding Methods to Existing Objects

You also can add methods to existing objects in the same way as we just added properties in the preceding topic; you just assign a function name to the name of the method you want, like this: object.method = function.

We’ve been adding properties and methods to objects one at a time, but you also can use prototypes to add properties or methods to all objects of a particular type simultaneously. We saw an example of this in Chapter 19. In that example, I wanted to add a method named sqrt to all Number objects that returned the square root of the number. For example, you could use that method like this:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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