Skip to content

Instantly share code, notes, and snippets.

@owskio
Last active August 29, 2015 14:04
Show Gist options
  • Save owskio/a89bb412a16caa79a737 to your computer and use it in GitHub Desktop.
Save owskio/a89bb412a16caa79a737 to your computer and use it in GitHub Desktop.
Eliminating library prefixes without JavaScripts with
//...
use = curry(function (obj,fn) {
//WHY: Implements qualified references in Javascript,
// without using Javascript's 'with'.
// Javascript doesn't allow us to alter the scope
// of a given piece of code programmatically without
// using 'with'. But 'with' has been labeled a 'bad
// part'. Because it is inefficient, and in some
// browsers, can duck-punch the global object. So I
// created a combinator which takes an object with
// potentially many references, and then breaks it
// out such that the callback gets called with those
// references 'dereferenced'.
//
//EXAMPLE;
// var o = {a:1,b:2};
// use(o,function(a,b){
// return a + b;
// }); // returns 3
var list = argList(fn),
args = [];
for (var i in list) {
var argName = list[i],
arg = obj[argName];
args.push(arg);
}
return fn.apply(this,args);
}),
//...
@owskio
Copy link
Author

owskio commented Aug 2, 2014

'Scope Doping' ... kind of like Silicon Doping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment