YUI recommends YUI3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This documentation is no longer maintained.
YAHOO.lang.augmentProto
YAHOO.lang.augmentProto
You may be familiar with this method as YAHOO.augment
. See the history of augmentProto for background and recommendations for syntax.
In this example, a class has been created then augmented with YAHOO.util.EventProvider
to provide custom event functionality.
Click the Send button to send the instance of the new class a request.
YAHOO.lang
comes bundled with the YAHOO Global Object. To add the YAHOO Global Object, include the following in your markup:
If you are using any other YUI component on your page, you should already have YAHOO.lang
available.
This example creates a custom class, then augments it with YAHOO.util.EventProvider
(functionality included in the YUI Event Utility). Using the packaged functionality of EventProvider
, the code for Foo
is able to focus on the functionality unique to its purpose.
If Foo
were a part of a class hierarchy, it would be improper to include EventProvider
in the inheritance chain, since the purpose of the two are fundamentally different.
Unlike extend
ed classes, the relationship between a class and the classes augmenting it is not an indication of type hierarchy. The intent of augmentProto
is to aid in extracting nonessential behaviors or behaviors shared by many classes, allowing for a composition-style class architecture.
This may appear similar to multiple inheritance, but it's not. augmentProto
simply adds the public methods and members from one class prototype to another class prototype. Instances of the augmented class will not pass instanceof
tests for the class(es) which augmented it.
augmentProto
started its life as YAHOO.augment
way back in version 0.12 of YUI.
In version 2.2.0, it was moved into the YAHOO.lang
module. The alias YAHOO.augment
was added for backward compatibility.
In version 2.3.0, augment
became augmentProto
. Another alias, YAHOO.lang.augment
, was created for backward compatibility.
While these aliases should be around for a while, it's advisable to use YAHOO.lang.augmentProto
going forward to ensure that your code is as future-compatible as possible.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.
Copyright © 2013 Yahoo! Inc. All rights reserved.