contents   index   previous   next



Object()

syntax:

new Object([value])

where:

value - a value or variable, usually a primitive, to convert to an object.

 

return:

object - a new top level object.

 

description:

Create a new top level object. I a value is passed, convert the value to an object, else create a new object. The examples below illustrate several ways to use Object() and how to accomplish similar things using different strategies.

 

If Object() is invoked as a function instead of as a constructor (that is, without new), it performs a type conversion on value. That is, it returns value as data type Object.

 

see:

Internal objects

 

example:

/***************************************

First we create var s as a string data type.

Then we will convert s to an object data type, 

namely, to a String object.

***************************************/

// Create s as data type string

var s = 'my string';

// Display the data type 'string'

Screen.writeln(typeof s);

// Display 'my string'

Screen.writeln(s);

 

// Convert s to data type object (String object)

var o = new Object(s);

// Display the data type 'object'

Screen.writeln(typeof o);

// Display 'my string'

Screen.writeln(o);

 

/***************************************

Next we create var so as a String object --

in one statement.

***************************************/

// Create so as a String object in one statement

var so = new String('my string');

// Display the data type 'object'

Screen.writeln(typeof so);

// Display 'my string'

Screen.writeln(so);

 

/***************************************

Next we create var o as an Object object data type.

We add the property o.mystring.

Note that the property may be accessed as:

   o.mystring

   or

   o['mystring']

***************************************/

// Create a new top level object

var o = new Object();

// Add the property mystring

o.mystring = 'my string';

// Display the data type 'object'

Screen.writeln(typeof o);

// Display 'my string'

Screen.writeln(o.mystring);

// Display 'my string'

Screen.writeln(o['mystring']);

 


Object hasOwnProperty()