Name
new — NN 2 IE J1 ECMA 1
Synopsis
The new operator. This operator creates instances
of the following static objects:
ArrayBooleanDateFunctionNumberObjectRegExpString
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()
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access