Skip to content
Akin C edited this page Apr 15, 2018 · 16 revisions

Welcome to the Javascript-function-eval- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


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/abuse 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)

Content

The user interaction part should look like the content as seen below by starting "index.html" in a web browser.

ERROR: No image found!

Within the textarea, Javascript code could be included/written and by pressing the "COMPILE" button it will be performed! As a standard code value within the textarea an indirect eval call is implemented as should be seen in the picture above.

Note that all files should be placed in the same folder so that the functionality of the code is guaranteed.

Clone this wiki locally