Team LiB
Previous Section Next Section

Summary

JavaScript provides four types of objects: user-defined, built-in, browser, and document. This chapter focused on the fundamental aspects of all objects, as well as the creation and use of user-defined objects. JavaScript is a prototype-based, object-oriented language. New object instances are created with constructors, objects that initialize the properties of new instances. Every object has a prototype property that reflects the prototype of the constructor used to create it. When an object property is accessed, the interpreter first checks the object’s instance properties for the desired name. If it is not found, the properties of the object’s prototype are checked. This process repeats recursively until it has worked up the chain of inheritance to the top-level object. Most of the time in JavaScript, the creation and management of the objects is straightforward, and programmers are freed from such headaches as memory management. While user-defined objects can be used to create much more modular and maintainable scripts, many JavaScript programmers do not really use them, given the simplicity of their scripts. Instead, the various built-in, browser, and document objects are utilized. The next chapter begins the examination of such objects, starting with built-in objects, particularly Array, Math, Date, and String.


Team LiB
Previous Section Next Section