rss twitter

Array.insert(index, value) Prototype

Wenn wir schon dabei sind, hier das Ganze andersherum, als insert(index:int, value:*) Prototype. Beispiel für die Anwendung:

Actionscript:
  1. var arr:Array = new Array("a", "c", "d");
  2. arr = arr.insert(1, "b");
  3.  
  4. trace(arr); // a, b, c, d

Auch hier waren die Ergebnisse im Netz eher schlecht als recht und da ich mich in meinen Developing-Ordnern immer wieder verliere kann ich nun selbst hier schnell nachschauen und mir den Prototype kopieren. Feel free to do so as well.

Actionscript:
  1. Array.prototype.insert = function(index:int, value:*):Array {
  2.     var original:Array = this.slice(); // a, c, d
  3.     var temp:Array = original.splice(index); // c, d
  4.     original[index] = value; // b
  5.     original = original.concat(temp); // a, b, c, d
  6.     return original;
  7. };

Kommentar hinterlassen

Powered by WordPress | Free T-Mobile Phones for Sale | Thanks to Palm Pre Blog, Video Game Music and Get Six Pack Abs