natively negotiating sync vs. async...without callbacks

Getify Solutions getify at
Fri Dec 10 07:08:56 PST 2010

>   4. Control of execution (that is, the actuall calling of a function) is
> linear in the chain in the calling code, rather than being controlled by the
> code inside a function.

Another reason I feel it's important to address being able to retain control
of the execution of the chained functions in *my* calling code is the
awkwardness around function context objects and them losing their `this`

We know that this:

function foo(cb) {
var obj = {
   val: 1,
   bar: function() {
      this.val = (this.val || 0) + 1;
foo(; subject to the `this` binding being lost from "obj" and becoming
"window". So, we have to go through hoops to "bind" a function's `this`
tightly, with Function.prototype.bind(), or we create a manual anonymous
function wrapper, etc. While it's possible to correct for, obviously, it
creates extra work for the developer and is a common trap for subtle errors.


foo() @;

Since my calling code is in control of the execution of `bar`, I call it on
the proper object and `this` doesn't get lost.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list