Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created August 19, 2020 05:24
Show Gist options
  • Save velotiotech/e7dc5e320619e28f1d0e771b684008a8 to your computer and use it in GitHub Desktop.
Save velotiotech/e7dc5e320619e28f1d0e771b684008a8 to your computer and use it in GitHub Desktop.
// 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