Created
August 19, 2020 05:24
-
-
Save velotiotech/e7dc5e320619e28f1d0e771b684008a8 to your computer and use it in GitHub Desktop.
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
// All the variables and functions which are not exported are private within the module and cannot be used outside. Only the exported members are public and can be used by importing them. | |
// Here the businessList is private member to city module | |
const businessList = new WeakMap(); | |
// Here City uses the businessList member as it’s in same module | |
class City { | |
constructor() { | |
businessList.set(this, ['Pizza Hut', 'Dominos', 'Street Pizza']); | |
} | |
// public method to access the private ‘businessList’ | |
getBusinessList() { | |
return businessList.get(this); | |
} | |
// public method to add business to ‘businessList’ | |
addBusiness(business) { | |
businessList.get(this).push(business); | |
} | |
} | |
// export the City class as default module | |
export default City; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment