Sign in
Log inSign up

How do I access a class property within a nested function?

Deactivated User's photo
Deactivated User
·Jul 7, 2019

Consider the following code:

class Person{
     constructor(name){
          this.name = name
     }
     findFromDatabase(name){
          return new Promise(function(resolve,reject)){
               this.userData = DatabaseMethod(name) // This binds userData to the promise 
          })
     }
}

I intend to bind userData to the Person class, but using this.userData = ... Binds it to the promise. How can I achieve what I intended to do? Thanks.