Kamel:J*/lib/async.js
aus Kamelopedia, der wüsten Enzyklopädie
Hinweis: Leere nach dem Speichern den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Extras → Internetspuren löschen … → Individuelle Auswahl → Den kompletten Cache löschen
/* +-------------------------------------------------------------------------+ * | | * | Modul 2: Die Async-Klasse, um asynchrone Vorgänge behandeln zu können | * | mehr Erklärung gibt's woanders ... vielleicht ... | * | | * +-------------------------------------------------------------------------+ */ function Async ( arr, ondone ) { var asyncobj = this; for (var i=0; i< arr.length; i++) asyncobj.push(arr[i]); this.pointer = 0; this.ondone = ondone; this.nextElement = function() { return this[this.pointer+1]; }; this.currentElement = function() { return this[this.pointer]; }; this.start = function ( obj, ond ) { if (ond != null) { this.ondone = ond; } this.pointer = 0; this._control( obj ); }; this.continue = function ( obj ) { this.pointer++; this._control( obj ); }; this._control = function ( obj ) { console.log("_control", obj); if (this.pointer >= this.length) { if (typeof(this.ondone)=="function") { this.ondone( obj, this ); return; } if (typeof(this.ondone)=="object") // instanceof gibt hier nur ärger { this.ondone.continue( obj ); return; } } if (this[this.pointer]==null) return; if (typeof(this[this.pointer])=="function") { this.continue( this[this.pointer]( obj, this ) ); return; } if (typeof(this[this.pointer])=="object") //auch hier gibt's Probleme mit instanceof { this[this.pointer].start( obj, this ); return; } }; } Async.prototype = new Array ();