Thursday, November 15th, 2007
Using the Yahoo Global Object to Manage Object Inheritance and Composition
The Yahoo! UI team have “posted four new examples that step through some of the most important methods in the YUI Library — particularly YAHOO.lang.extend, YAHOO.lang.augmentObject, and YAHOO.lang.augmentProto. These methods are used internally in the library to manage inheritance and composition, and we think you’ll find them useful in your own code, too.”
- Creating Class Hierarchies with
YAHOO.lang.extend— explores the use ofYAHOO.lang.extendto build traditional class-style hierarchies in JavaScript; - Creating a Composition-Based Class Structure Using
YAHOO.lang.augmentProto— as Luke puts it, “the intent of augmentProto is to aid in extracting nonessential behaviors or behaviors shared by many classes, allowing for a composition-style class architecture”; in this example, he shows you how to do that by applying the YUI Event Utility’sEventProviderfunctionality usingaugmentProto; - Add Behavior to Objects or Static Classes with
YAHOO.lang.augmentObject—augmentObjectprovides functionality similar to that ofaugmentProto, but is designed for work with static classes where you want to confine your augmentation to the target object (rather than its prototype); - Combining Simple Data Sets with
YAHOO.lang.merge— in a different category,YAHOO.lang.mergeallows you to combine two objects together, outputting a third (new) object.












For those interested, the original article about “extend” is
http://kevlindev.com/tutorials/javascript/inheritance/index.htm
I feel incredibly old school for not keeping up with YUI changes and just now learning about these additions to the YAHOO global object.