Skip to content

Instantly share code, notes, and snippets.

@trevmex
Created May 10, 2011 18:12
Show Gist options
  • Select an option

  • Save trevmex/965022 to your computer and use it in GitHub Desktop.

Select an option

Save trevmex/965022 to your computer and use it in GitHub Desktop.
JavaScript template to make private functions testable
if (typeof NS === 'undefined' || !NS) {
var NS = {};
}
(function ($) {
NS.Klass = function(options) {
var settings = {
debug: false
},
private = {
// Public Functions
},
public = {
// Private Functions
};
if (options) {
$.extend(settings, options);
}
if (settings.debug) {
return $.extend({}, private, public);
} else {
return public;
}
};
})(jQuery);
var myClass = new NS.Klass(); // Regular usage
var myDebugClass = new NS.Klass({debug: true}); // Debug usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment