Creating Properties

Adding properties to our object is extremely simple. In this case, we need to first define parameters in the constructor as we did with the other objects. This allows us to pass values to the properties and set them when an instance of the object is created. After the object is created and the parameters are retrieved by the object’s constructor function, we create the properties and set their values. In the following example, we set the id, firstName, and lastName of each employee object that is created.

function employee(_id, _firstName, _lastName)
{
    this.id = _id;
    this.firstName = _firstName;
    this.lastName = _lastName;
}

As I said earlier, these properties are extremely easy to create and set within an object. The object’s ...

Get Ajax for Web Application Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.