I am working on a program that runs in ECMA 5.
All js files are use strict and this makes most suggestions online not usable as for example return new Promise.resolve is not usable in strict mode.
I am calling an async method to get an url and if a url is returned then the user should see a button that when pressed will forward the user to that page. I have this working with async and await. Now I want to move this from page load to do this after page is loaded so it doesn't affect page rendering. in case the service is down.
var self = this;
$(document).ready(function () {
alert("ok");
var promise = $.get(myService.getMyUrl());
$.when.apply(self, promise).then(function() {
self.url(arguments);
self.showButton(self.url() ? true : false);
});
});
The alert gets shown so I know I'm getting here, but the problem is that I can't make the function an async function and simply await the result so how do I resolve the promise?
As stated above I already tried new Promise.resolve() (gives: using a variable without declaring it is not allowed in strict mode) and this code also does not work as arguments is not readable in strict mode. Any other ideas?
Eventually it was solved with
myService.getMyUrl().done(function(data) {
self.myUrl(data);
self.showButton(myUrl ? true : false);
});
Apparently my question was unclear to some people. If things are unclear ask what is unclear as well as maybe read the question again slowly. Misinterpretation is clearly a thing.