Mega Code Archive

 
Categories / JavaScript Tutorial / Object Oriented
 

Declaration and Instantiation

Objects are created by using the new keyword followed by the name of the class. var oObject = new Object(); var oStringObject = new String(); The first line creates a new instance of Object and stores it in the variable oObject; The second line creates a new instance of String and stores it in the variable oStringObject. The parentheses aren't required when the constructor doesn't require arguments, so these two lines could be rewritten as follows: var oObject = new Object; var oStringObject = new String;