HTML and CSS Reference
In-Depth Information
Programmers who have experience with other object orientated languages are al-
ways initially drawn to constructor functions. They provide a certain familiarity,
and appear to provide a class based typing system. Programmers are then invari-
ably annoyed when these classes do not provide the same features they are used
to with classes in other languages.
Finally, we can look at the final line of the extends function:
return new E();
This is simply returning a new object created by the E constructor. Since we only need to
write the extends function once however, we will not forget the new keyword.
You can now use the extends function to create some objects:
> p1 = extend(person)
> p1.firstName = 'John'
> p1.lastName = 'Smith'
> p1.age = 34
As the examples above illustrate, semi colons are actually optional in JavaScript.
It is highly recommended that all statements are terminated with semi-colons
however, since JavaScript will automatically add them when they are missing,
and in some cases they will not be added where they are expected. This is an-
other common source of hard to find bugs, for instance, the following function
returns undefined :
function a() {
Search WWH ::

Custom Search