Skip to content

Instantly share code, notes, and snippets.

@andy0130tw
Created October 7, 2014 13:15
Show Gist options
  • Save andy0130tw/92f39f64e72a7b99d90d to your computer and use it in GitHub Desktop.
Save andy0130tw/92f39f64e72a7b99d90d to your computer and use it in GitHub Desktop.
JavaScript Function Isolation
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