Javascript Object reference

Javascript build-in Object object reference.

Create objects:

To create an object: new Object([param])
You uses the new keyword to create an object.
To use as a function: Object([param])
When the Object object is used as a function the return will be an object as well.
param: The param argument is optional. If it is absent an empty object is returned.

If the param argument is present, the result can be one of the following:

  1. If the param is a string, a primitive string is returned.
  2. If the param is a number, a primitive number is returned.
  3. If the param is a bolean, a primitive boolean is returned.
An example of using the new Object(param):
<script type="text/javascript">
var stringObj= new Object("This is the string.");
document.write("String: "+stringObj+"<br>");
var numObj= new Object(2011);
document.write("Number: "+numObj+"<br>");
var booleanObj= new Object(true);
document.write("Boolean: "+booleanObj+"<br>");

General information about the object member types:

  1. Prototype created methods, properties or constants can only be used on instances of an object or on a primitive datatype.
  2. Constructor created methods, properties or constants can NOT be used on instances of an object or on a primitive datatype.

Prototype Methods:

Syntax: hasOwnProperty(propname)
Objects can have its own local properties and properties inherited from its prototype object.

This method provides the ability to distinguish between the inherited properties and noninherited local properties.

Return value: true if the object contains 'propname' as its own local properties.

false if the object does not contain 'propname' as a property or 'propname' is an inherited property.

propname: A string name of a property, as this method will be using in his test.
An example of using the hasOwnProperty() :
<script type="text/javascript">
var obj = {color:"red"};
document.write("Is color an own property: "+obj.hasOwnProperty('color')+"<br>");
document.write("Is valueOf an own property: "+obj.hasOwnProperty('valueOf')+"<br>");

Prototype Properties:

Syntax: Object.prototype.constructor
This property of the Object.prototype holds the reference back to the Object object.
Important note: This is the same as the constructor property of an instantiated object

Constructor (Object) Properties:

Syntax: Object.constructor
The constructor property is a reference to the function that will be invoked to create a Object object.

© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.