natevw / fermata

Succinct native REST client, for client-side web apps and node.js. Turns URLs into (optionally: magic!) JavaScript objects.
328 stars 24 forks source link

What about .call/.apply? #28

Open natevw opened 11 years ago

natevw commented 11 years ago

Consider this code:

queue()
    .defer(api.db.doc1.get)
    .defer(api.calculator.post, "sin(2.71828182846)")
.await(function (e, thing1, thing2) {
   console.log(e, thing1.number + thing2.result);
});

In this case, the queue code must .apply our arguments to our "functions". But our URL instances do not support call/apply — call(ctx, arg, cb) might issue an HTTP "CALL" request at best, and apply() just extends the URL oddly!

I wonder if it'd work to have () return a String object instead of a primitive string — then we could assign its own call/apply properties and the code would be rewritten like so:

.defer(api.calculator.post(), "sin(2.71828182846)")

Kinda odd/hacky, but not sure a better way to support this situation.