Skip to content

Instantly share code, notes, and snippets.

@oakfang
Created November 9, 2015 16:48
Show Gist options
  • Save oakfang/46e14b9de65c9f407789 to your computer and use it in GitHub Desktop.
Save oakfang/46e14b9de65c9f407789 to your computer and use it in GitHub Desktop.
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