Wednesday, July 10, 2013

Object Instantiation in Javascript

May be its simple post.But its big enough to differentiate the object and variable in javascript.

var someVariable = "Some text";
var someOtherVariable = ["Name1","Name2","Name"];

The above lines are just variable declaration with keyword "var".
In javascript,Object Instantiation also can be done in the same fashion but with curly  open and closed braces {}.

Example:
var mYObject = {
                 Name:"Murugesa Pandian"; 
                 WhoIsHe:function() { return "Working as Programmer";}
                }


Now mYObject is an Object which holds the property or attribute or you may be call "Member" ,Name and method(function) WhoIsHe.

Call it as
document.write(mYObject.Name);
document.write(myObject.WhoIsHe());