HTML and CSS Reference
In-Depth Information
If you want to create a new object to refer to a different person, you need to add these prop-
erties and methods all over again. This is not a major problem for the properties of an ob-
ject, since you would need to provide values for those properties anyway, but it is a major
inconvenience for methods. For instance, you would need to write the following:
> obj2 = {}
> obj2.firstName = 'Albert'
> obj2.lastName = 'Jones'
> obj2.age = 28
> obj2.increaseAge = function() {
this.age++;
}
//
An alternative approach is to include the properties and methods inside the {}
separating properties/methods with commas, and properties/methods from their
values with colons:
obj2 = {
firstName: 'Albert',
lastName: 'Jones',
age: 28,
increaseAge: function() {
this.age++;
}
}
This is going to become a major inconvenience, especially if you have a large number of
methods on your object.
 
Search WWH ::




Custom Search