Mac os x web server - JavaScript Programmer’s Reference Unless you assign the result

JavaScript Programmer’s Reference Unless you assign the result of the new operation, an object will simply consume memory. You need to store a reference to it at the time it is instantiated. You can do this by assigning it to a variable or a property of another object, passing it in to a function and making sure it gets retained in there, or storing it as an element in an array. Warnings: . You can refer to objects without the parentheses but then you are not referring to a constructor function but to the object itself. The behavior varies between browsers and depends on the kind of object being instantiated and probably depends on whether it is a wrapper for a primitive data type or a more complex aggregated type. . These all appear to create the same kind of object in both MSIE and Netscape myObject = Object(); myNewObject = new Object(); myOtherObject = new Object; These do not: myBoolean = Boolean(); myNewBoolean = new Boolean(); myOtherBoolean = new Boolean; . In the case of the Boolean, Number, and String object types, only the first form will initialize the new object with a value. Placing the result of these examples in document.write() statements illustrates the behavior. You may want to examine the objects returned in more detail by developing an object inspector script. See also: Boolean(), Constructor function, constructor property, Garbage collection, Global object, Memory leak, new, Number(), Object constant, Object object, Object.prototype, Reference counting, String() Cross-references: ECMA 262 edition 2 section 15.1.1 ECMA 262 edition 2 section 15.1.3.1 ECMA 262 edition 2 section 15.2.2.2 ECMA 262 edition 3 section 15.2.2 1578

Leave a Reply