Tuesday, May 1, 2012

JavaScript: OOP Fundamentals

An overview on what are the data types, objects, object types, constructor and 'arguments' keyword available in JavaScript are discussed below.

JavaScript Data types

UNDEFINED
NULL
NUMBER
STRING
BOOLEAN

Later three are extensively used.

How to determine the data type?

TYPEOF operator

Example: alert(typeof true);

Here this will return Boolean.

OBJECT

A collection of properties which can be primitive data types, other objects or functions. The "new" keyword tells the JavaScript to create an object for the function.

Types
 

a. Native Objects

These are by default supplied by the JavaScript. A few examples include Date, Image, Array, Math, etc., 
 
b. Host Objects
 
These objects are available for use in JavaScript related to the browser and supplied by the browser. A few examples include navigator, window, document, etc.,
 
c. User-Defined Objects
 
These are user/programmer designed objects.
 
Constructor

Also can be termed as a constructor function that can be used to create an object.

Example: var objDate = new Date();

Here objDate is the OBJECT and Date() is the CONSTRUCTOR.

"this" Keyword

The scope this keyword is limited to the object created for a specific function.

ARGUMENT

In every function there is a variable named argument which holds an array of argument values passed. This can be overwritten.

for(iCounter=0;iCounter
{
alert(“This is Argument Number - ” + iCounter + “. Argument Value is : ” + arguments[iCounter]);
}

No comments:

Post a Comment

Please leave your comments here...