Thursday, 24 April 2014

Jquery Objects

Jquery Objects
// Creating an object with the constructor:
var person1 = new Object;
person1.firstName = "John";
person1.lastName = "Doe";
alert( person1.firstName + " " + person1.lastName );
// Creating an object with the object literal syntax:
var person2 = {
firstName: "Jane",
lastName: "Doe"
};
alert( person2.firstName + " " + person2.lastName );

// As mentioned, objects can also have objects as a property.
var people = {};
people[ "person1" ] = person1;
people[ "person2" ] = person2;
alert( people[ "person1" ].firstName );
alert( people[ "person2" ].firstName );
If a property is accessed that has not been defined, it will return a type of undefined.
// Properties that have not been created are undefined.
var person = { name: "John Doe" };
alert( person.email ); // undefined