Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

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

Chapter 2: Javascript Primer > Understanding Objects

UNDERSTANDING OBJECTS

Objects are collections of properties, each property having a name and value. Properties can contain any type except for undefined, and are assignable even after the object is created. Arrays, functions, and regular expressions are all objects. Numbers, strings, and Booleans are also objects, but they are immutable. You can instantiate objects in a couple ways. One is to use the new keyword:

image
var myObject = new Object();

Code snippet is from new-object.txt

The new keyword invokes a constructor function, or more commonly constructor. The constructor initializes the newly created object. The following code snippet shows a constructor for an object called Zombie, which initializes its property name and then instantiates a Zombie object using new. The this keyword refers to the current object, and it cannot be assigned a value, although you can save its value in another variable.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint