Last active
August 11, 2017 18:31
-
-
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.
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
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