Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: new Function() Date: Wed, 30 Sep 2015 21:12:42 +0100 Organization: A noiseless patient Spider Lines: 27 Message-ID: <87h9mb64zp.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="29491"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19EzACROljS9b1BTBPHk3Zk99yeONgLofk=" Cancel-Lock: sha1:p+ac9WujyTMZeDa5JnQNSN242r8= sha1:6lfE+xSSrXRs8tkMyJOfkaRp3ro= X-BSB-Auth: 1.a0525035c44d77f96825.20150930211242BST.87h9mb64zp.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:28768 Jay Braun writes: > I am having some trouble experimenting with 'new Function()' as an > alternative to 'eval()'. OK, but unless this is just a learning exercise, why are you changing code that works for code that does not yet work? Using new Function and then calling the resulting function is not any safer than calling eval, if that is your reason. > Simple on-line examples of 'new Function()' show the "new" function > being constructed in-line by some JavaScript code. That's not what is > occurring here, and my attempts to apply the examples have failed. Well something is probably wrong with the "new Function" call, but how can anyone possibly help if you don't show the code? > In particular, the browser console indicates that funcName() is not > recognized. This indicates a significant misunderstanding. The result of the new Function call is a function itself -- if it gets a name at all, it will be because you store the result in variable. -- Ben.