Developer Network Home - Help

Yahoo! UI Library: YAHOO Global Object

Yahoo! UI Library: YAHOO Global Object

The YAHOO Global Object provides a single global namespace within which all YUI Library code resides. It must be included on every page that utilizes the YUI Library, and it must appear before any of the other YUI component.

The YAHOO Global Object also contains a number of methods that are used throughout the library.

Getting Started

The YAHOO Global Object must be included before any of the other script files that are part of the YUI library:

YUI dependency configurator.

YUI Dependency Configurator:

Instead of copying and pasting the filepaths above, try letting the YUI dependency Configurator determine the optimal file list for your desired components; the Configurator uses YUI Loader write out the full HTML for including the precise files you need for your implementation.

Note: If you are loading components via the YUI Loader, this component is included in the YUI Loader package — you do not need to load it separately. If YUI Loader is on the page, so is the YAHOO Global Object.

Where these files come from: The files included using the text above will be served from Yahoo! servers; see "Serving YUI Files from Yahoo!" for important information about this service. JavaScript files are minified, meaning that comments and white space have been removed to make them more efficient to download. To use the full, commented versions or the -debug versions of YUI JavaScript files, please download the library distribution and host the files on your own server.

Order matters: As is the case generally with JavaScript and CSS, order matters; these files should be included in the order specified above. If you include files in the wrong order, errors may result.

Using the Utility Methods in YAHOO

YAHOO.namespace

The YAHOO Object automatically generataes namespaces for YAHOO.util, YAHOO.widget, and YAHOO.example. These namespaces are reserved for script that is included in the YUI release. Additional namespaces can be created to contain custom applications built upon the library:

YAHOO.lang

YAHOO.lang contains javascript language utilities and extensions that are used in the YUI library.

YAHOO.lang.hasOwnProperty

YAHOO.lang.hasOwnProperty can be used to filter out properties that were added to the Object prototype when iterating over an object that is being used as a hash table. This feature is natively supported across all current A-Grade browsers, but it wasn't added to Safari until recently; all internal usage of the hasOwnProperty test within YUI will use the version in YAHOO.lang for the forseeable future, and we recommend that you do the same in your own implementations. YAHOO.lang.hasOwnProperty will use the native browser function unless it isn't available.

YAHOO.lang.extend

YAHOO.lang.extend provides a simple mechanism for setting up the prototype, constructor, and superclass properties for objects that are extending other objects. It also prevents the constructor of the extended object (ie, the superclass) from being executed twice. YAHOO.lang.extend was relocated into the YAHOO.lang package in version 2.5.2. YAHOO.extend is a deprecated alias for YAHOO.lang.extend.

YAHOO.lang.augment

YAHOO.lang.augment provides a way to reuse code by applying some or all of the prototype properties in one object to another object. YAHOO.augment is a deprecated alias for YAHOO.lang.augment.

YAHOO.log

YAHOO.log is included in the Yahoo Global Object so that logging code can be included anywhere in YUI code (or in your own code) even if the YUI Logger Control is not on the page; this prevents errors from appearing as you begin removing debugging instrumentation from your project. YAHOO.log executes YAHOO.widget.Logger.log if the Logger Control is available; otherwise, it does nothing. See the documentation for the Logger Control for more information about how to make use of it in your work.

YAHOO_config and YAHOO.env

YAHOO.env contains information the browsing environment. In particular, it contains information about all of the YUI components that have been loaded on the page. This data is accessible by any component by using YAHOO.env.getVersion, but it is especially useful for environments where the library is dynamically loaded.

Instead of using polling techniques to determine when YAHOO and the rest of the YUI Library is loaded, you can define within YAHOO_config a callback method that will be invoked every time a new YUI module is inserted inserted into the page. Your callback method, defined as YAHOO_config.listener, will receive as an argument an information object containing the following information:

property type description
name string The name of the YUI component that has just loaded. The name is an arbitrary string corresponding to a YUI component. Current YUI component names can be found in the YUI Module Names section below.
version string The version in use (e.g., "2.5.2").
build number The build number of the current version. This is a continuously incremented integer that will grow larger with each version of the library.
versions array An array containing the string version information for all versions of this component that have been registered during the current page session. This can help identify issues that were the result of multiple versions of a module on the page.
builds array An array containing the numeric build information for all versions of this component that have been registered during the current page session.
mainClass object The principal object/class for the registered component. This object will have been stamped with its current version and build information. If mainClass.VERSION != version or mainClass.BUILD != build, multiple versions of pieces of the library have been loaded, potentially causing issues.

In the extended code sample below, the YAHOO_config object is used to register a listener that fires when YUI components are loaded:

YUI Module Names

Each YUI component has a corresponding module name that is used as a unique identifier within YUI scripts. For example, the Event Utility is internally referred to as "event". The Yahoo Global Object and other components (such as the YUILoader Utility) make use of these unique module names. Here is the full list of YUI module names.

YUI on Mobile: Using YAHOO Global Object with "A-Grade" Mobile Browsers

About this Section: YUI generally works well with mobile browsers that are based on A-Grade browser foundations. For example, Nokia's N-series phones, including the N95, use a browser based on Webkit — the same foundation shared by Apple's Safari browser, which is found on the iPhone. The fundamental challenges in developing for this emerging class of full, A-Grade-derived browsers on handheld devices are:

  • Screen size: You have a much smaller canvas;
  • Input devices: Mobile devices generally do not have mouse input, and therefore are missing some or all mouse events (like mouseover);
  • Processor power: Mobile devices have slower processors that can more easily be saturated by JavaScript and DOM interactions — and processor usage affects things like battery life in ways that don't have analogues in desktop browsers;
  • Latency: Most mobile devices have a much higher latency on the network than do terrestrially networked PCs; this can make pages with many script, css or other types of external files load much more slowly.

There are other considerations, many of them device/browser specific (for example, current versions of the iPhone's Safari browser do not support Flash). The goal of these sections on YUI User's Guides is to provide you some preliminary insights about how specific components perform on this emerging class of mobile devices. Although we have not done exhaustive testing, and although these browsers are revving quickly and present a moving target, our goal is to provide some early, provisional advice to help you get started as you contemplate how your YUI-based application will render in the mobile world.

More Information:

The YAHOO global works without known issues in tested mobile environments. In a future release of the library, YAHOO.env.ua will be expanded to include detection for certain "A-Grade" mobile browsers. Until then, you can use the following code to detect a number of interesting mobile browsers:

Support & Community

The YUI Library and related topics are discussed on the on the ydn-javascript mailing list.

In addition, please visit the YUIBlog for updates and articles about the YUI Library written by the library's developers.

Filing Bugs & Feature Requests

The YUI Library's public bug tracking and feature request repositories are located on the YUI SourceForge project site. Before filing new feature requests or bug reports, please review our reporting guidelines.

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings