Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

underscore #1

Open
dvv opened this issue Mar 5, 2011 · 1 comment
Open

underscore #1

dvv opened this issue Mar 5, 2011 · 1 comment

Comments

@dvv
Copy link

dvv commented Mar 5, 2011

Mind to publish it also in form of underscore.js plugin?
TIA,
--Vladimir

@refractalize
Copy link
Owner

Not sure how you wanted it done, but due to the async'ness, you won't be able to mix and match zo and underscore functions like this:

_([1, 2, 3]).
    zoMap(function (item, mapTo) {
        setTimeout(function () {
            mapTo(item + 1);
        }, 500);
    }).each (function (item) {
        console.log(item);
    });

There's no guarantee that the mapTo will be executed before the each. Once in async-world, always in async world. So, the best I can do is something like this:

var _ = require('underscore'),
    zo = require('zo').zo;

_.mixin({
    zo: function (items) {
        return zo(items);
    }
});

_([1, 2, 3])
    .zo()
    .map(function (item, mapTo) {
        setTimeout(function () {
            mapTo(item + 1);
        }, 500);
    })
    .results(function (items) {
        console.log(items);
    });

Where the call to .zo() starts the zo namespace and it's all zo methods from there on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants