Mar 24, 2006

prototype.jsのオブジェクト汚染

/latest 以外のディレクトリに置いているページで使っているコンテンツリスト生成用JavaScriptがprototype.jsのObject汚染におもくそひっかかっててメニューぶっ壊れ状態になってたことに今頃気付いた。連想配列とfor-inループの組み合わせで大量死発生。ということでリンク先で提案されている以下のコードを組み込んで対処した。

    Object.prototype.forEach = function(func){
        for(var key in this){
            if(!(key in this.constructor.prototype)){
                func(this[key],key,this)
            }else if(this[key] != this.constructor.prototype[key]){
                func(this[key],key,this)
            }
        }
    };
    obj.forEach(function(value,key,self){
        alert([value,key]);
    });

ンモー

エントリを編集します。

wikieditish message: Ready to edit this entry.











拡張機能