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


Groups > comp.lang.javascript > #28768

Re: new Function()

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
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> (permalink)
References <a52a763b-4769-4ca6-8f82-9785514df782@googlegroups.com>
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

Show key headers only | View raw


Jay Braun <lyngwyst@gmail.com> 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.

<snip>
> 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.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

new Function() Jay Braun <lyngwyst@gmail.com> - 2015-09-30 11:28 -0700
  Re: new Function() "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-30 21:15 +0200
  Re: new Function() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-30 21:12 +0100
    Re: new Function() Jay Braun <lyngwyst@gmail.com> - 2015-09-30 20:30 -0700

csiph-web