tags:

views:

55

answers:

3

I've been seeing code that looks like:

myObj.doSome("task").then(function(env) {
    // logic
});

Where does then() come from?

+3  A: 

I suspect doSome returns this, which is myObj, which also has a then method. Standard method chaining...

if doSome is not returning this, being the object on which doSome was executed, rest assured it is returning some object with a then method...

as @patrick points out, there is no then() for standard js

hvgotcodes
+2  A: 

To my knowledge, there isn't a built-in then() method in javascript.

It appears that whatever it is that doSome("task") is returning has a method called then.

If you log the return result of doSome() to the console, you should be able to see the properties of what was returned.

console.log( myObj.doSome("task") ); // Expand the returned object in the
                                     //   console to see its properties.
patrick dw
A: 

In this case then() is a class method of the object returned by doSome() method.

Vlad Lazarenko