Created
November 9, 2015 16:48
-
-
Save oakfang/46e14b9de65c9f407789 to your computer and use it in GitHub Desktop.
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 exporter(publics, privates) { | |
privates = privates || {}; | |
var all = Object.assign({}, publics, privates); | |
publics.__test = function (t) { | |
var str = t.toString().match(/\{((.|\s)*)\}/)[1]; | |
with (all) { | |
eval(str); | |
} | |
}; | |
return publics; | |
} | |
function closureFactory(a, b) { | |
function privateFunc(foo) {return foo + 1;} | |
return exporter({ | |
func: function () {return a + b} | |
}, {privateFunc, a, b}) | |
} | |
var ins = closureFactory(1, 2); | |
ins.__test(function () { | |
console.log(a, b); | |
console.log(privateFunc(5)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment