Name
new — NN 2 IE J1 ECMA 1
Synopsis
The new
operator. This operator creates instances
of the following static objects:
Array
Boolean
Date
Function
Number
Object
RegExp
String
An expression with this operator evaluates to an instance of the object. Syntax rules allow naming the static object, the static object with empty parentheses, and the static object with parameters in parentheses:
var myArray = new Array var myArray = new Array() var myArray = new Array("Larry", "Moe", "Curly")
Only the last two examples are guaranteed to work in all scriptable
browser versions. With the exception of the Date
object, if you omit assigning parameters during the object creation,
the newly minted instance has only the properties that are assigned
to the prototype of the static object.
Example
var now = new Date()
Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.