https://stackoverflow.com/questions/26150232/resolve-javascript-promise-outside-function-scope This works fine, but is there an easier way to do this? If not, is this a good practice?
No, there is no other way to do this - the only thing I can say is that this use case isn't very common. Like Felix said in the comment - what you do will consistently work. It's worth mentioning that the reason the promise constructor behaves this way is throw safety - if an exception you did not anticipate happens while your code is running inside the promise constructor it will turn into a rejection, this form of throw safety - converting thrown errors to rejections is important and helps maintain predictable code.