Last active
January 30, 2017 21:15
-
-
Save andycole/4cbc1dc48da07f648050 to your computer and use it in GitHub Desktop.
AMD Module Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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