MzTreeView.prototype.load = function(id) 表示对MzTreeView对象的扩展。其效果跟这么写是一样的
function MzTreeView(){
  this.load = function(id)
{
  var node = this.node[id], d = this.divider, _d = this._d;
  var sid = node.sourceIndex.substr(node.sourceIndex.indexOf(d) + d.length);
  var reg = new RegExp("(^|"+_d+")"+ sid +d+"[^"+_d+d +"]+("+_d+"|$)", "g");
  var cns = this.names.match(reg), tcn = this.node[id].childNodes; if (cns){
  reg = new RegExp(_d, "g"); for (var i=0; i <cns.length; i++)
  tcn[tcn.length] = this.nodeInit(cns[i].replace(reg, ""), id); }
  node.isLoad = true;
}; 
}
在jsp页面调用的话;
var MzTreeView = new MzTreeView();
MzTreeView .load();

解决方案 »

  1.   

    例如可以对js的原生对象String进行扩展String.prototype.toNum = function(){
       return ($d(this))?Number(this.split("px")[0]):null;
    }然后在jsp页面可以直接使用var str = "csdn";
    str.toNum();//只要type为string,就拥有了toNum()的属性方法。可以直接进行调用  
      

  2.   

    哦。谢谢了。
    还有个问题,希望能赐教-------------
    我以下代码是先输出“你好”,然后就没有显示“2222”和“1111”了。
    是不是你给的函数不对?
    <html>
    <head>
    <script type="text/javascript">
    String.prototype.toNum = function(){ 
     alert("nihao"); return ($d(this))?Number(this.split("px")[0]):null; 

    </script>
    </head>
    <body>
    <script type="text/javascript">
    var str="111";
    alert("2222"+str.toNum());</script>
    </body>
    </html>
    以上代码
      

  3.   

    //如果传入的参数为null或undefined,则返回fasle;否则返回true; 
    window.$d = function(obj){return (obj != undefined);}