Skip to content

Instantly share code, notes, and snippets.

@srkirkland
Created September 1, 2011 17:34
Show Gist options
  • Save srkirkland/1186718 to your computer and use it in GitHub Desktop.
Save srkirkland/1186718 to your computer and use it in GitHub Desktop.
Template for creating componentized javascript design
(function (purchasing, $) {
//Private Property
var options = {};
//Public Property
purchasing.AddressData = { Id: null, Name: 'Default' };
//Public Method
purchasing.options = function (o) {
$.extend(options, o);
};
purchasing.init = function() {
//Do your jquery document ready stuff in here
$("#element").click(function() {
//On click stuff
if (options.showAlert){
alert(helper());
}
});
};
//Private function
function helper() {
return "Hello, world!";
};
} (window.purchasing = window.purchasing || {}, jQuery));
<script>
//Setup your options
purchasing.options({ modifyUrl: '@Url.Action("EditAddress")', showAlert: true });
$(function () {
//init the public method
purchasing.init();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment