Skip to content

Instantly share code, notes, and snippets.

@josephmcasey
Last active August 11, 2017 18:31
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 josephmcasey/d57e76fb815d078a64c1d7f059a735f5 to your computer and use it in GitHub Desktop.
Save josephmcasey/d57e76fb815d078a64c1d7f059a735f5 to your computer and use it in GitHub Desktop.
Shows a basic implementation of a JavaScript class which can utilize private members while having a publicly accessible interface.
let Klass = (function () {
// To add private members using a WeakMap, check out the link below.
// https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Contributor_s_Guide/Private_Properties
function foo (params) {
// Code
}
class Klass {
constructor(params = {default}) {
try {
foo()
} catch (exception) {
return exception
}
}
}
return Klass
})()
export default Klass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment