HTML and CSS Reference
In-Depth Information
> obj3.firstName = 'Jim'
> obj3.firstName = 'Duffey'
> obj3.age = 42
> obj3.increaseAge()
As you can see we have retained the method already defined on its prototype.
This section is not intended to imply classes have no value in JavaScript, instead it is inten-
ded to demonstrate what objects truly are in JavaScript, and to suggest that there are viable
ways of writing JavaScript that does not utilize classes.
There are potential pitfalls in this implementation. For instance, if you forget to set a prop-
erty on the newly cloned object, it will retain the value from the object it was cloned from:
this may or may not be correct, and could become a source of bugs.
Although we will examine more advanced approaches to object creation below, the ap-
proach to objects examined in this section has a lot to recommend it.
Search WWH ::

Custom Search