anonymous function - Javascript IIFE - back door? -


this question has answer here:

there try or know how acces variable in anonymous function??

example

var test = "hi";  (function() {     var test = "bye";      // outputs "bye"     console.log(test); })();  // outputs "hi" console.log(test); 

as can see last log return "hi" want "bye" know way value "bye" in example ??

running function creates scope; "bye" defined in scope; , scope never visible outside function.

if have access iife, can modify exports variable outside scope.

if iife inside named function in same cross-origin code, can display outer function:

var toto = function() {     var test = "hi";      (function() {         var test = "bye";          // outputs "bye"         console.log(test);     })();      // outputs "hi"     console.log(test);     }  console.log(toto); 

outside these cases, nothing can done; design. cross-origin restriction on function code display there prevent access code not belong you. clever people have thought through; doubt backdoor exists.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -