Skip to content

Instantly share code, notes, and snippets.

@andycole
Last active January 30, 2017 21:15
Show Gist options
  • Save andycole/4cbc1dc48da07f648050 to your computer and use it in GitHub Desktop.
Save andycole/4cbc1dc48da07f648050 to your computer and use it in GitHub Desktop.
AMD Module Template
// MYMODULE CLASS DEFINITION
// ==========================
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else {
factory(window.jQuery);
}
}(function ($) {
var MyModule = function (element, options) {
'use strict';
var mymodule = this;
this.$element = $(element);
this.options = $.extend({}, MyModule.defaults, options);
this.$element.on('mouseover', function () {mymodule.publicMethod();});
};
MyModule.defaults = {
someVar: 50,
nextVar: 'Some text'
};
MyModule.prototype = {
myAttribute: 'value',
_privateMethod: function () {
//Does something private.
},
publicMethod: function () {
//Does something public.
}
};
return MyModule;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment