Skip to content

Instantly share code, notes, and snippets.

@manuelbieh
Last active December 10, 2015 18:29
Show Gist options
  • Save manuelbieh/4475118 to your computer and use it in GitHub Desktop.
Save manuelbieh/4475118 to your computer and use it in GitHub Desktop.
Make private functions public for testing
function foo() {
var _private = function() {
return 'myPrivateFunction';
};
return {
foobar: function() {
return 'foobar' + _private();
},
barfoo: function() {
return 'barfoo' + _private();
}
/* strip-start */, _testExpose: function(test) {return eval(test);}/* strip-end */
}
};
var example = new foo();
console.log(example._testExpose('_private()'));
// in your build script:
// myfile = myfile.replace(/\/\* strip-start (.*) strip-end \*\//gi, '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment