Skip to content

Instantly share code, notes, and snippets.

@capfsb
Last active November 2, 2017 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capfsb/ea54be01156b1eb1d6f7091d8cb4d907 to your computer and use it in GitHub Desktop.
Save capfsb/ea54be01156b1eb1d6f7091d8cb4d907 to your computer and use it in GitHub Desktop.
Globals
function Pure(fn, context) {
this.context = context;
eval('this.fn=' + fn.toString());
}
Pure.prototype.withGlobals = function(useGlobals) {
this.useGlobals = 1;
return this;
}
Pure.prototype.use = function(vars) {
if (!this.useGlobals) {
var windowVars = [];
for (var w in window) {
if (w.indexOf(['console']) < 0)
windowVars.push(w);
}
eval('var ' + windowVars.join(',') + ';');
}
for (var i in vars) {
eval('var ' + i + ' = vars[i]');
}
eval('this.fn=' + this.fn.toString());
if (this.context) {
this.fn = this.fn.bind(this.context);
}
return this.fn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment