var Iterator = function (fn) {
var coroutine = null;
var cofn_this = null;
var yield = function() {
coroutine.apply(cofn_this, arguments);
}
// support IE.
// NOTE: IE eval("function(){}") does not return a function object.
eval('fn = ' + fn.toString());
return function(cofn, cothis){
coroutine = cofn;
cofn_this = cothis;
return fn.apply(this)
};
}
Array.prototype.forEach = new Iterator(function () {
for (var i = 0; i < this.length; i ++) {
yield(this)
}
});
// example.
this.display = window.alert;
var A = [1,2,3,4,5];
A.forEach(function(it){
this.display(it)
}, this);