看来结论有两个(或许还不该这么早下结论)
1、关心js's namespace的人少。
2、还不知道namespace的人也不在少数
再放几天就结贴

解决方案 »

  1.   

    YahooUI里也实现在这个功能,代码如下
    var YAHOO = function() {    return {        /**
             * Yahoo presentation platform utils namespace
             */
            util: {},        /**
             * Yahoo presentation platform widgets namespace
             */
            widget: {},        /**
             * Yahoo presentation platform examples namespace
             */
            example: {},        /**
             * Returns the namespace specified and creates it if it doesn't exist
             *
             * YAHOO.namespace("property.package");
             * YAHOO.namespace("YAHOO.property.package");
             *
             * Either of the above would create YAHOO.property, then
             * YAHOO.property.package
             *
             * @param  {String} sNameSpace String representation of the desired
             *                             namespace
             * @return {Object}            A reference to the namespace object
             */
            namespace: function( sNameSpace ) {            if (!sNameSpace || !sNameSpace.length) {
                    return null;
                }            var levels = sNameSpace.split(".");            var currentNS = YAHOO;            // YAHOO is implied, so it is ignored if it is included
                for (var i=(levels[0] == "YAHOO") ? 1 : 0; i<levels.length; ++i) {
                    currentNS[levels[i]] = currentNS[levels[i]] || {};
                    currentNS = currentNS[levels[i]];
                }            return currentNS;        }
        };} ();
      

  2.   

    namespace 我早在使用了,比如 Using("System.Web.UI.WebControls.MzTreeView");
    且只看你提供的这段示例,还是停留在很初级的阶段。
      

  3.   

    to: meizz能否看看你的namespace示例
      

  4.   

    to 唠叨:为了脚本的清淅方便利用,有的时候很有必要加入namespace的功能。
      

  5.   

    YAHOO.namespace实际上就是这个<script language="javascript">function __using(ns)
    {
     var nsParts = ns.split(".");
     var root = window; for(var i=0; i<nsParts.length; i++)
     {
       root[nsParts[i]] = root[nsParts[i]] || {};
       root = root[nsParts[i]];
     }
     return root;
    }var com={
    f : function() {
    alert("com function");
    },
    util : {
    f : function() {
    alert("com.util function");
    }
    }
    };var b=__using("com");
    b.f();
    var c=__using("com.util");
    c.f();
    </script>
      

  6.   

    能否看看你的namespace示例