By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,983 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,983 IT Pros & Developers. It's quick & easy.

multiple actions in eval() on safari asynchronous

P: 1
First I have a script file like:

alert('a');
if(***) alter('b');

saved on the server.

I'm using AngularJS developing a mobile app which reads and executes it using eval().

On iOS safari alter('b') will come up first then alter('a') and it seems codes after eval() will run asynchronously.

However on Android & PC Chrome the sequence is as expected as alter('a')->alter('b')->things after eval().

How can I run run scripts synchronously on Safari? Many thanks.
Mar 4 '17 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,320
i am not aware of such behaviour of eval but 2 things - 1st: using eval is pretty much very bad practice - i've never seen a reason to use it except bad design of a software or (in the old days) evaluating a JSON response from a XMLHttpRequest. 2nd: if something is async there is usually 2 solutions - you can use a timeout which is very bad practice as well - or refactor everything so that the code uses callbacks whenever it should proceed with the next step - which would be the preferable solution. ES6 provides promises that can be used to achieve the same goal - and basically transpile into an appropriate callback-chain.
Mar 16 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.