SoFunction
Updated on 2025-02-28

Methods for implementing yield in javascript


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