Last active
November 13, 2020 22:45
-
-
Save jywarren/4aba01d07a22d53579b5b862cc8f1f33 to your computer and use it in GitHub Desktop.
Template for simple JS library
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
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; | |
} |
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
module.exports = function privateMethod(options) { | |
} |
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
module.exports = function publicMethod(options) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment