My yld NPM - callbacks/promises alternative I'd like feedback on my callbacks/promises alternative, please.

The yld repository

var yld;

yld = (function () {
'use strict';

var slice, clearer, defer, prepare, yld;

slice = Array.prototype.slice;

clearer = {
    yld: {
        value: undefined
    },
    throw: {
        value: undefined
    }
};

Object.freeze(clearer);

defer = typeof process === 'object' &amp;&amp; typeof process.nextTick === 'function' ? process.nextTick : function nextTick(closure) {
    setTimeout(closure);
};

prepare = function* (parent) {
    var proto, generator, fnGenerator, response;

    proto = {
        yld: function (fn) {
            var parent;

            parent = this;

            return function () {
                var generator, proto, fnGenerator;

                generator = prepare(parent);
                proto = generator.next().value;
                generator.next(generator);
                fnGenerator = fn.apply(proto, arguments);
                generator.next(fnGenerator);

                return Object.create(proto, clearer);
            };
        },
        next: function (value) {
            defer(function () {
                generator.next(value);
            });
        },
        nextCb: function () {
            var value;

            value = slice.call(arguments);

            defer(function () {
                generator.next(value);
            });
        },
        throw: function(error) {
            defer(function() {
                fnGenerator.throw(error);
            });
        }
    };

    if (parent !== undefined) {
        proto.parent = Object.create(parent, clearer);
    }

    generator = yield proto;
    fnGenerator = yield null;

    while (true) {
        response = yield defer(function () {
            fnGenerator.next(response);
        });
    }
};

yld = function (fn) {
    return function () {
        var generator, proto, fnGenerator;

        generator = prepare();
        proto = generator.next().value;
        generator.next(generator);
        fnGenerator = fn.apply(proto, arguments);
        generator.next(fnGenerator);

        return Object.create(proto, clearer);
    };
};

return yld;
}());

if (typeof module === 'object' &amp;&amp; module.exports !== undefined) {
    module.exports = yld;
}
Interesting question;

I honestly can't follow the code, and I tried a while. I like to think of myself as above average in JavaScript, which means that from a readability/maintainability perspective you have a problem. It might be related to the fact that you have no comments in there ;)

Some minor style tips


For easier reading you can merge your var declarations with initial assignments, this

var parent;

parent = this;


becomes then

var parent = this;

You make a shortcut for Array.prototype.slice, but you use it only once, I would throw away the shortcut and simply go for value = Array.prototype.slice.call(arguments);.
There is no need to keep creating a function in your loop, just create the function outside of your loop.

while (true) {
   response = yield defer(function () {
      fnGenerator.next(response);
   });
}