Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28720

Re: alternatives to eval() for this case

Path csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: alternatives to eval() for this case
Date Sat, 26 Sep 2015 09:33:01 +0200
Organization PointedEars Software (PES)
Lines 39
Message-ID <360817097.BH5zBMaEkf@PointedEars.de> (permalink)
References <1a8362bb-6ff2-41a9-93b2-5469b67ffd02@googlegroups.com> <mu53pe$ktl$1@speranza.aioe.org>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1443252783 24062 eJwNxcEBwCAIA8CZEIh0HIJm/xHsfS4dhtmBRKRSnqTN/xjvh7PZPBUWJXq4bFVpAX2rW7UfK74RmA== (26 Sep 2015 07:33:03 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Sat, 26 Sep 2015 07:33:03 +0000 (UTC)
User-Agent KNode/4.14.2
X-User-ID eJwFwYEBwDAEBMCVqPxjHAn2H6F3MCqfH4IHi+19g5vYMG/Xg2ipjsgqHcn0cblzhE37DDbeHN6vxHXe2g9ftRWk
Cancel-Lock sha1:plvb9TYAEVoHg/Zxyz2uM3GL7gM=
X-NNTP-Posting-Host eJwFwYEBwDAEBMCV8LxknFL2HyF3ASo7nUGPjb01dquOa3NG0/zQy8bkS4WAFkUpUcW/QD8REhBX
Xref csiph.com comp.lang.javascript:28720

Show key headers only | View raw


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


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