Click the button below to call methods on an augmented static class.
YAHOO.lang comes bundled with the YAHOO Global Object.
If you are using any other YUI component on your page, you should already have YAHOO.lang available.
Static classes, such as
YAHOO.util.Dom, are implemented as object literals with keys corresponding to public class methods. As such, static classes aren't candidates for instantiation or prototype extention. To add functionality to static classes, you need to work with the class's object literal.
In this example,
augmentObject is used to add a set of behaviors to a static class.
We'll create a namespace
YAHOO.example.addons to hold common packages of static methods and members. In this namespace, we'll create a set of logging functions.
Now a targeted class that would benefit from these methods can add them using
augmentObject while keeping its source focused and unique.
augmentObject works in similar fashion to
augmentProto. In fact,
augmentObject under the hood. However, rather than adding functionality to class definitions (i.e. function prototypes),
augmentObject can work with any object, including object literals and class instances.
extend for other techniques to help manage your code structure.