Alexander (HH): Browser-Kompatibilität

Beitrag lesen

Moin Moin!

Selbst die Funktion schreiben

Oder jemanden finden, der sowas mal eben aus dem CVS-Repository kramt und hiermit ohne Garantie und unter Ausschluß jeglicher Gewährleistungsansprüche der Öffentlichkeit spendet.

Nur bleibt's nicht beim splice, weil antike IEs auch einige andere Array-Methoden nicht kennen. Die sind aber relativ trivial zu implementieren.

  
if (null==Array.prototype.push) {  
 Array.prototype.push=function()  
 {  
  for (var i=0; i<arguments.length; i++) this[this.length]=arguments[i];  
  return this.length; // Verhalten von JS > 1.2  
 };  
}  
if (null==Array.prototype.pop) {  
 Array.prototype.pop=function()  
 {  
  return this[this.length--];  
 };  
}  
if (null==Array.prototype.shift) {  
 Array.prototype.shift=function()  
 { // schnell implementiert, aber nicht schnell ;-)  
  this.reverse();  
  var rv=this.pop();  
  this.reverse();  
  return rv;  
 };  
}  
if (null==Array.prototype.unshift) {  
 Array.prototype.unshift=function()  
 { // schnell implementiert, aber nicht schnell ;-)  
  this.reverse();  
  for (var i=arguments.length-1; i>=0; i--) this[this.length]=arguments[i];  
  this.reverse();  
  return this.length;  
 };  
}  
if (null==Array.prototype.splice) {  
 Array.prototype.splice=function(start,count)  
 {  
  var removed=new Array();  
  var tail=new Array();  
  var i;  
  if (start<0) start+=this.length;  
  for (i=0; i<count; i++) removed.push(this[start+i]);  
  for (i=start+count; i<this.length; i++) tail.push(this[i]);  
  this.length=start;  
  for (i=2; i<arguments.length; i++) this[this.length]=arguments[i];  
  for (i=0; i<tail.length; i++) this.push(tail[i]);  
  return removed;  
 };  
}  

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so".