Skip to content

@domenic /q-bind.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Q.bind
// From discussion at https://groups.google.com/d/msg/q-continuum/68ro20aB358/7kUCAF19qqAJ
// Naive version
function fAsync(a, b) {
if (a) {
return Q.reject(new Error());
}
if (b) {
return Q.resolve(42);
}
return Q.resolve();
}
// With `Q.call`
function fAsync(a, b) {
return Q.call(function f(a, b) {
if (a) {
throw new Error();
}
if (b) {
return 42;
}
}, null, a, b);
}
// With `Q.bind`
var fAsync = Q.bind(function f(a, b) {
if (a) {
throw new Error();
}
if (b) {
return 42;
}
});
// Could also pass context, bound args as with `Function.prototype.bind`.
@ryanwitt

+1 for composability

@domenic
Owner

@ryanwitt Are you on q-continuum? I started the discussion about it over there :)

@ryanwitt

yes. it's just that i'm anti-social

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.