Last active
November 2, 2017 00:53
-
-
Save capfsb/ea54be01156b1eb1d6f7091d8cb4d907 to your computer and use it in GitHub Desktop.
Globals
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
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