Created
October 7, 2014 13:15
-
-
Save andy0130tw/92f39f64e72a7b99d90d to your computer and use it in GitHub Desktop.
JavaScript Function Isolation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var root=this; | |
function getIsolationScript(){ | |
//getting key of global attrs | |
var buffer=""; | |
for(var x in root)buffer+="try{var "+x+"=void 0}catch(e){}"; | |
//the name of the top-level variable | |
// should be manually set. | |
buffer+="var window={}"; | |
return buffer; | |
} | |
function isolate(){ | |
eval(getIsolationScript()); | |
// | |
//we are in the sandbox! | |
// | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment