Skip to content

Instantly share code, notes, and snippets.

@jywarren
Last active November 13, 2020 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jywarren/4aba01d07a22d53579b5b862cc8f1f33 to your computer and use it in GitHub Desktop.
Save jywarren/4aba01d07a22d53579b5b862cc8f1f33 to your computer and use it in GitHub Desktop.
Template for simple JS library
module.exports = myLibrary = function constructor(o) {
let privateMethod = require('./privateMethod.js')({}); // we can pass in an object full of options
let publicMethod = o.publicMethod || require('./publicMethod.js'); // allow methods to be overridden via options object
let publicApi = {
element: el, // the HTML element into which the library is inserted, if any
publicMethod: o.publicMethod, // here we expose any public methods we want
options: o // options can be exposed too
};
return publicApi;
}
module.exports = function privateMethod(options) {
}
module.exports = function publicMethod(options) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment