topical media & game development

talk show tell print

professional-web-03-yahoo.js / js

  Copyright (c) 2006, Yahoo! Inc. All rights reserved.                                                                                                    
  Code licensed under the BSD License:                                                                                                                                                                                                                           
  version: 0.11.0                                                                                                                                         
The Yahoo global namespace @constructor

  var YAHOO = window.YAHOO || {};
Returns the namespace specified and creates it if it doesn't exist YAHOO.namespace("property.package"); YAHOO.namespace(""); Either of the above would create, then
parameter: {String} ns The name of the namespace
returns: {Object} A reference to the namespace object

  YAHOO.namespace = function(ns) {
      if (!ns || !ns.length) {
          return null;
      var levels = ns.split(".");
      var nsobj = YAHOO;
      // YAHOO is implied, so it is ignored if it is included
      for (var i=(levels[0] == "YAHOO") ? 1 : 0; i<levels.length; ++i) {
          nsobj[levels[i]] = nsobj[levels[i]] || {};
          nsobj = nsobj[levels[i]];
      return nsobj;
Uses YAHOO.widget.Logger to output a log message, if the widget is available.
parameter: {string} sMsg The message to log.
parameter: {string} sCategory The log category for the message. Default categories are "info", "warn", "error", time". Custom categories can be used as well. (opt)
parameter: {string} sSource The source of the the message (opt)
returns: {boolean} True if the log operation was successful.

  YAHOO.log = function(sMsg, sCategory, sSource) {
      var l = YAHOO.widget.Logger;
      if(l && l.log) {
          return l.log(sMsg, sCategory, sSource);
      } else {
          return false;
Utility to set up the prototype, constructor and superclass properties to support an inheritance strategy that can chain constructors and methods.
parameter: {Function} subclass the object to modify
parameter: {Function} superclass the object to inherit

  YAHOO.extend = function(subclass, superclass) {
      var f = function() {};
      f.prototype = superclass.prototype;
      subclass.prototype = new f();
      subclass.prototype.constructor = subclass;
      subclass.superclass = superclass.prototype;
      if (superclass.prototype.constructor == Object.prototype.constructor) {
          superclass.prototype.constructor = superclass;

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.