Alex Kocharin
unread,Sep 23, 2014, 8:34:06 PM9/23/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com
There seem to be a conflict between chaining api and promise-based api. Both of them use return value, but chaining api returns `this`, and promise-based one returns promise.
Is it possible to use both at the same time?
Here is some abstract example. Suppose we have a class:
```js
function Message(text) {
var self = Object.create(Message.prototype)
self.text = text
return self
}
Message.prototype.send = function(server, callback) {
servers[server].doStuff(callback)
return this
}
```
Which can be used this way:
```js
Message("text")
.send("server1", function() { console.log("message sent to server 1") } )
.send("server2", function() { console.log("message sent to server 2") } )
```
Some users want to use promises. Ideally, it'll look like that:
```js
Message("text")
.send("server1")
.then( function() { console.log("message sent to server 1") } )
.send("server2")
.then( function() { console.log("message sent to server 2") } )
```
I'm sure it's possible with prototype injection into promise, but it surely sounds weird. Is there a better way?
--
// alex