Sign in
Log inSign up

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

Dandy Cheng's photo
Dandy Cheng
·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.

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct