civ3

编程好玩

导航

两个有用的数组扩展方法

    Array.prototype._push=function(c){
        for(var j in this)
        if(this[j]==c)return false;
        this.push(c);
        return true;
    }
    Array.prototype.kick=function(c){
        for(var j in this)
        if(this[j]==c){
            this[j]=null;
            var sf=function(x,y){
                if(x==null)return -1;
                else return 0;
            }
            this.sort(sf).pop();
        }
    }
_push是无重复的压栈;
kick是指定元素出栈;
新发现:js中不仅支持“函数直接量”,还支持“函数作为局部变量”!
其实还想到了写成this.sort(new Function("x","y","......")).pop();
的样子,但是又觉得那样就更迂腐了,呵呵!

posted on 2005-08-28 17:48  civ3's .NET studying  阅读(344)  评论(0编辑  收藏  举报