Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28720
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: alternatives to eval() for this case |
| Date | 2015-09-26 09:33 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <360817097.BH5zBMaEkf@PointedEars.de> (permalink) |
| References | <1a8362bb-6ff2-41a9-93b2-5469b67ffd02@googlegroups.com> <mu53pe$ktl$1@speranza.aioe.org> |
Joao Rodrigues wrote: > On 25/09/15 14:26, Jay Braun wrote: >> One of the few cases where eval() seems to be regarded as >> acceptable is an AJAX case like this, where a script on the server >> side is being requested: > > There are other ways to insert a script into a document than using AJAX More importantly, there are a lot *better* ways to do that. One problem is that this does not work well in strict mode, where the eval scope chain is empty, and it does not work cross-origin without CORS. > The problem, I think, is if you need the scripts to execute in an > expected order. If so, you may try to mark the downloaded script as not > async [1], using: > > script.async = false; > > [1] <http://caniuse.com/#feat=script-async> If you read more carefully, you will realize that this does not work. “async=false” not only requires HTML5 support, but it is the *default* there: <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#Attributes> pp. For scripts to be *executed* in a specific *order*, you need a promise-based approach like requireJS, where you define() the dependencies of a module, then require() it, and only when it has become available you (automagically) execute the code that depends on it. <http://requirejs.org/> -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
alternatives to eval() for this case Jay Braun <lyngwyst@gmail.com> - 2015-09-25 10:26 -0700
Re: alternatives to eval() for this case Danny <dann90038@gmail.com> - 2015-09-25 15:39 -0700
Re: alternatives to eval() for this case Jay Braun <lyngwyst@gmail.com> - 2015-09-25 15:50 -0700
Re: alternatives to eval() for this case Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-09-26 00:35 -0300
Re: alternatives to eval() for this case Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-26 09:33 +0200
Re: alternatives to eval() for this case Jay Braun <lyngwyst@gmail.com> - 2015-09-26 20:14 -0700
Re: alternatives to eval() for this case Martin Honnen <mahotrash@yahoo.de> - 2015-09-27 10:30 +0200
Re: alternatives to eval() for this case Jay Braun <lyngwyst@gmail.com> - 2015-09-27 07:45 -0700
csiph-web