タグ

codeとarray.pushに関するC_Lのブックマーク (1)

  • MacIE5でArray.pushを実装

    MacIE5でArray.pushを実装 スポンサードリンク Tweet MacIE5でArray.pushが必要になったんで、作りました。以下のコードをJavaScriptのコードに入れておくと、Arrayオブジェクトにpushメソッドが追加されます。pushメソッドが既にある場合は、上書きしません。 // Array.pushをMacIE5に実装 if (typeof Array.prototype.push != 'function') { Array.prototype.push = function (f){ this[this.length] = f; } } 使うときは普通に var x = ['hoge', 'fuga']; x.push('hage'); alert(x.length); // 3 var s = ''; for (var i = 0; i < x.len

    C_L
    C_L 2008/09/01
    MacIE5などArray.push()が定義されていないとき、それらを使えるように関数を定義します。それらが実装されているブラウザでは、上書きしません。
  • 1