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.extend
YAHOO.lang.extend
JavaScript supports the notion of class hierarchies. As in other object-oriented languages, you can create generic classes, then create specialized subclasses that add or override functionality of the superclass.
Click the "Show Inheritance" button to do some evaluation of the created object.
var chicken = new Chicken();
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.
In this example, we create a class YAHOO.example.Bird
then create a subclass YAHOO.example.Chicken
.
instanceof
many classesUnlike classes composed with augmentation, extending subclasses are also considered instances of their superclass and all classes higher up the inheritance tree.
We'll create an instance of YAHOO.example.Chicken
and run some instanceof
and method tests against it.
Take a look at YAHOO.lang.augmentProto
and YAHOO.lang.augmentObject
for different strategies of managing your code structure.
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.