K
K
Karen Kratyan2011-10-18 23:49:25
JavaScript
Karen Kratyan, 2011-10-18 23:49:25

Javascript: Eval || "new Function"?

What is better to use? Or another option? ..
upd: Which option is better to use to run js code from the server, for example?

var codeRun = "console.log('now run code')";

//Which code is better?

//run function
console.log('new Function:');
(new Function(codeRun))();

//or eval
console.log('eval:');
eval(codeRun);

jsfiddle.net/pSVNp/1/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leprechaun, 2011-10-19
@Leprechaun

eval is a potential security hole.
Use only at your own risk.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question