Skip to content

Instantly share code, notes, and snippets.

@pnmcosta
Last active April 3, 2017 18:50
Show Gist options
  • Save pnmcosta/802d1ac947b2a049a1b0f138c267abea to your computer and use it in GitHub Desktop.
Save pnmcosta/802d1ac947b2a049a1b0f138c267abea to your computer and use it in GitHub Desktop.
Example CommonJS Module Wrapped by Brunch with options, private and public methods and properties
/**
* Example CommonJS Module Wrapped by Brunch with options, private and public methods
* Usage with defaults: require("brunch.commonjs.options.module")()
* Usage with options: require("brunch.commonjs.options.module")({myOptionName:false})
*/
"use strict";
// require's and constants
const $ = require("jquery");
// module public properties and methods
var me = {
myOptionName:true
}
me.myMethod = function(arg1){
}
// private properties and methods
var someOtherVar = "woopwoop";
function myPrivateMethod(){
}
// example initialization
$(document).ready(function () {
});
// example extend options (uses jQuery) and export of module
module.exports = function (options) {
if (options)
me = $.extend({}, me, options);
return me;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment