cujojs/when — Issue #21: Should when.js Promises implement valueOf() and/or toString()?
Author: briancavalier
Created: 2012-02-16 16:57:28+00:00
State: open

Implementing `valueOf()` could be interesting in that it would allow the valueOf a resolved promise to return the resolution value, which would allow some operators, like ==, +, etc. to work on resolved promises. For example, doing a comparison directly on a promise `if(resolvedPromise == 1) {...}`.

The potential downside is that people might *misuse* this, or if they aren't familiar with using promises, could be confused into using it incorrectly. For example `setInterval(function() { if(promise == 1) doSomething(promise.valueOf()); }, 100)'`, rather than `when(promise, doSomething);`

Not sure yet what the value would be in implementing `toString()` to return something like `"[object Promise]"` when unresolved, and `String(resolvedValue)` when it is resolved. But we should at least think through it.