Question

I have a function build that synchronously returns an object, that in turn contains a function run. This function returns a thunk and hence can be called using yield and a library such as co.

Basically the call looks like this:

yield build().run();

Now, the problem is that I want to make sure that the yield refers to run, not to build. How do I do that, without introducing a temporary variable as in the following snippet?

var temp = build();
yield temp.run();

Any ideas?

PS: I'm running this code on Node.js 0.11.x using the ´--harmony´ flag.

Was it helpful?

Solution

Little has higher precedence over the member operator and the call operator, so you're safe. Here's a reference for you MDN Operator Precedence. The yield is pretty far down there.

If you wanted to group yield to the build() call, you'd need an explicit grouping.

(yield build()).run()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top