AS1 OOP: Custom Object Classes
         by senocular  

Shared Values Between Instances
With each constructor call when creating an instance, values from the function definition are copied into the new object instance being created. In some cases, you may have a value that is constant for every instance of an object - something that never changes and always remains the same with each instance made. In such a situation it would be favorable for each instance to not have its own copy, but rather to share one single copy thereby avoiding redundancy. You don't need to have a clock in your living room for each member of your family. Everyone can look at the same clock to see what time it is. That way you don't need to by or deal with separate clocks.

Class methods are particularly considerable in these situations. Hardly will there ever be a time where each object instance will need a unique copy of function. It would be much more efficient to have a single shared function representing a class method and not copies for each instance created. This not only avoids the redundancy in having unnecessary copies, but it also means that should you ever decide to change a method of a class, you would only need to change one shared function definition and not one for each instance. Why set all the living room clocks when you would only need to set just one?

This kind of sharing is possible using prototypes.
 

Prev Page
 



SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.