Why does a returned Promise not have a method on it .then when logged to the console?

Viewed 90

I understand that a new promise has a .then method on it.

But when I console log the promise returned from getUserData('jeresig') I get this object logged to the console (with no .then method).

Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }

Is .then actually on the new promise object or perhaps it only gets added to the object later asynchronously?

So does that mean .then is called asynchronously even though it looks synchronous?

let Promise = require('bluebird'),
    GitHubApi = require('github'),

let github = new GitHubApi({
  version: '3.0.0'
});

function getUserData (user){
    return new Promise(function(resolve, reject){
      github.user.getFollowingFromUser({
        user: user,
        per_page: 2
      }, function(err, res){
        if (err){ reject(err) }
        else {
          resolve(res)
        }
      })
    })
}

console.log(getUserData('jeresig'))

  // .then(function(data){
  //   console.log('data', data)
  // })
  // .catch(function(error){
  //   console.log('error', error)
  // })
3 Answers
Related