Last active
August 29, 2015 14:04
-
-
Save owskio/a89bb412a16caa79a737 to your computer and use it in GitHub Desktop.
Eliminating library prefixes without JavaScripts with
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
//... | |
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); | |
}), | |
//... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
'Scope Doping' ... kind of like Silicon Doping