October 2006
Intermediate to advanced
288 pages
5h 55m
English
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 ...
Read now
Unlock full access