某个著名博客上面的一段孤立的代码,大体结构为
(function() {这儿为具体代码})(); 
这样的函数,自己不运行,也无名称,其他人怎么调用阿;
具体如下:
(function() {
    var p = P(N.ui),
    um;
    p.agC = C();
    um = p.agC.ae(p.eJ, true);
    um.av = function(az, A) {
        this.acf = 'key-' + U.bF(5);
        this.aw(az, A);
    };
    um.ax = function(A) {
        p.agC.ar.ax.call(this, A);
        A = A || O;
        this.gH = A.tag || '';
        this.ve = E.aM(A.sbody);
        this.Hw = A.handler || '';
        this.bxE = !!A.useclass;
        this.Uw = A.noselect || 'noselect';
        this.I('onchange', A.onchange || F);
    };
    um.hZ = function(az) {
        this.dK = E.aM(az);
        if (!!this.dK) this.aS();
    };
    um.aS = function() {
        this.Lc();
        for (var i = this.dH.length - 1; i >= 0; this.aGg(this.dH[i]), i--);
    };
    um.hA = function(bD, auu) {
        bD = bD || 'id';
        var aP = [];
        for (var i = 0,
        l = this.dH.length; i < l; aP.push(this.dH[i][bD]), i++);
        return aP.join(auu || ',');
    };
    um.aX = function() {
        V.I(document, 'mouseup', this.Gb.D(this));
        V.I(document, 'mousemove', this.tf.D(this));
    };
    um.aGg = function(as) {
        if (!!as[this.acf]) return;
        as[this.acf] = true;
        as = this.aZd(as);
        V.I(as, 'dragstart', V.aN);
        V.I(as, 'mousedown', this.rW.D(this));
    };
    um.Yd = function(as) {
        return ! !as[this.acf];
    };
    um.aZd = function(as) {
        var G = !!this.Hw && E.bc(as, this.Hw) || null;
        return G && G[0] || as;
    };
    um.FK = function(aec, aeK) {
        if (!!aeK) B.eq ? document.body.onselectstart = F: E.ad(document.body, this.Uw);
        else B.eq ? document.body.onselectstart = null: E.ag(document.body, this.Uw);
    };
    um.Lc = function() {
        this.dH = (!this.bxE ? E.bc(this.dK, this.gH) : E.ah(this.dK, this.gH)) || [];
    };
    um.rW = F;
    um.tf = F;
    um.Gb = F;
})(); 

解决方案 »

  1.   

    这种函数可以称为匿名函数。它是不用调用的,在加载的时候就执行了。var test;
    (function(){test=123}());
    alert(test);//弹出123var tmp=function(){var test='abc'; return test;}();
    alert(tmp);//弹出abc这种函数最多的用处就是闭包。
      

  2.   

    (表达式)  
    ()运算符计算并且返回表达式的值(注意不要和方法调用后面的‘()’混淆)
    则 (function(){})返回这个function
    (function())()返回这个function并且用'()'调用执行这个function
      

  3.   

    匿名函数!var p = P(N.ui),
      um;
      p.agC = C();um 是全局变量。外面可以访问
      

  4.   

    (function() {这儿为具体代码})();  匿名函数,定义的时候直接被调用
    最后一个括号意味着调用。这样做好处:
    函数体内定义的var和function,只在函数体内有效,不会造成不同文件之间的变量冲突