Java Reference
In-Depth Information
wraps the primitive value. You can get the primitive value using the valueOf() method on
the returned object. Calling the function without an argument creates an empty object.
The following code illustrates how to use Object :
var str = "Hello";
// Assigns a wrapper for str to p1 because str is a primitive type
var p1 = new Object(str);
print("p1.valueOf() is", p1.valueOf());
print("typeof p1 is", typeof p1);
print("p1.valueOf() === str is", p1.valueOf() === str);
var msg = new String("Hello");
// Assigns the reference of msg to p2. new Object(msg) returns
// the reference of msg because msg is an object.
var p2 = new Object(msg);
print("p2 === msg is", p2 === msg);
print("p2.valueOf() is", p2.valueOf());
print("typeof p2 is", typeof p2);
print("p2.valueOf() === msg is", p2.valueOf() === msg);
p1.valueOf() is Hello
typeof p1 is object
p1.valueOf() === str is true
p2 === msg is true
p2.valueOf() is Hello
typeof p2 is object
p2.valueOf() === msg is false
Table 4-11 contains the list of properties and methods of Object with their
descriptions.
 
 
Search WWH ::




Custom Search