JRS: In article <11**********************@g14g2000cwa.googlegroups .com>
, dated Fri, 12 Aug 2005 14:00:13, seen in news:comp.lang.javascript,
st********@gmail.com posted :
Is this an alternative to eval(). Admittidly, I have done *very* little
testing (ran it a few times in Firefox), but it seemed to work
suprisingly well with simple expressions such as "alert('hello')"
function _eval(s) {
var h = document.getElementsByTagName("HEAD")[0];
var o = document.createElement("SCRIPT");
o.text = s;
h.appendChild(o);
h.removeChild(o);
}
It is not so in general, because eval is a function that returns a
value, and yours only returns undefined.
Also, it uses methods available only in more recent browsers.
There is in fact nothing at all wrong with using eval for the intended
purposes; the error is using eval as an addressing mechanism where there
is a more direct method (and in using eval where nothing is actually
needed instead).
See FAQ 4.40 & 4.39, and
<URL:http://www.merlyn.demon.co.uk/js-other.htm#eval>.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.