|
||
| Inside Technique : Extending JavaScript with Function Pointers : Creating Custom Objects Function pointers provide the foundation for creating your own custom objects.
When you create a custom object
you add methods to the object by assigning references to functions to members of your object. Below we
create a simple square object:
First, notice how a function can act as a constructur for an object. Calling new functionName creates and returns a new instance of the object. With this object instance, you can access the different methods and properties. Each method is created by adding a property to the object that is assigned to a function elsewhere in your script. It is important to recognize that each time you use the Custom objects demonstrate one scenario of the usefulness of the function pointer. Through the remainder of this article, we explain how function pointers can also be used to fix compatibility issues between browsers. You can either extend the browser with new functionality or override the built-in implementation simply by rewriting the functionality. Next we explain how to take advantage of the fact that all built-in JavaScript functions are actually methods of a particular object Page 1:Extending JavaScript with Function Pointers © 1997-2000 InsideDHTML.com, LLC. All rights reserved. |