-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Javascript´s eval function takes a string as an argument. This string can contain Javascript code which will be performed:
eval
(
//Outputs "Hello World!"
'alert("Hello World!")'
);
The example above is a direct call of the function eval and it could bring with its use some disadvantages. One is the ability to change code within the scope of a function in which eval is used. For avoiding that, one could use strict mode it seems or wrap eval in a nested function:
function anyFunction(code)
{
//Nested function
(function()
{
eval
(
'alert(code)'
);
})();
}
The second issue is that the performance costs could be high. The solution for that is an indirect call:
(0,eval)(code);
It seems the listing above is just one example for an indirect eval call. The syntax could be read as follows:
Code Part | Explanation |
---|---|
(0,eval)
|
Follows the rule regarding to the comma operator and evaluates to a value |
(code)
|
Is the argument of the function _**eval**_(or any other function) |
STILL IN WORK!
This knowledge was gained:
-
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman
-
Github markdown, syntax highlight of code blocks in the table cell asked by Ziav and answered by Pokechu22
-
Is there a way to get colored text in Github Flavored Markdown? asked by Roman A. Taycher and answered by Brett Zamir
-
Perfection Kills - Global eval. What are the options? by kangax