0

I am new to es6 classes and I want to know what can be the solution to my problem. Below is the code:-

class userscomp {

  registerUser(userJoinData) {

    var usersModelsData = new usersModel({
      // Users Model
    })

    usersModelsData.save(function (err, userSavedData, numAffected) {

      if (err)
        throw err
      else if(numAffected === 1 && !err) {

        var authModelsData = new authsModel({
          // Auth Model
        })

        authModelsData.save(function(err, authSavedData, numAffected) {

          if (err)
            throw err
          else if(!err)
           return true // Return from the registerUser function
        })
      }
    })
  }
}

In the above case my return doesn't work. Is there a way to return within the nested scope. Any help is greatly appreciated

tumulr
  • 133
  • 4
  • 11
  • Nope. Perhaps instead you could look at [promises](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise)? – Nebula Feb 13 '16 at 12:25
  • This has nothing to do with ES6 or classes specifically, it's just an asynchronous callback. There is no way to `return`. In ES6, you should use promises to solve this. – Bergi Feb 13 '16 at 13:28
  • @Bergi Thanks a lot for the answer and I will look into promises – tumulr Feb 13 '16 at 14:07

0 Answers0