1

I have a class file

class User {
    constructor(){

    }
    submitUser(){
        db.query("select * from users where id=1",(err,data)=>{
            Object.assign(this,data[0]);
        })
    }

    getInfo(){
        console.log(this);
    }
}

I use mysql module for queries. What I wanna achieve is:

let user = new User();
user.submitUser();
user.getInfo();

I want to run user.getInfo after db query is completed

  • Maybe this helps you, as TJ pointed out there are a lot of answers around. So before asking a question on stackoverflow first do a research: :) Here a link to a sandbox with a playaround regarding your question: https://codesandbox.io/s/q4xkpy8pm6?fontsize=14 – hyde Apr 09 '19 at 15:55

0 Answers0