I have been working on some new code and found a need to make a series of calls to server-side PHP, where it would process data in a MySQL database, munch on some data and then return a result. I wanted to perform this operation inside a class constructor, so I could essentially do something like this:
The problem is that a constructor in JavaScript cannot be declared async and you cannot place an await on your server call. So, something like this fails:
To get around this, I learned a new trick, so I thought I would share:
Small modification to the original code above and done:
I threw post this together fairly quickly, but hopefully it makes sense. ☺️
