Quiz
- Can you go over the significance of why we do export { LocalStore }; or export { DataStore };
Sure. This is our module interface. The module gets to decide what name(s) are exported (and can be imported). Something that isn't exported is completely private. (Unlike, say, Python, where importing a module gets you access to all the names.)
In the
main-module, there's a matchingimportstatement. Let's look at that. main-module.jsIt's also possible to rename while importing, so a module can
and the importing module can:
- I would like to discuss more about the adjustments that were made in Main.
Sure. Let's talk about them again. The highlights:
- load from local storage
- If there were saved order, reconstruct the checklist
- Does this mean values from other projects uploaded to Heroku might be accidentally accessed because the projects share the origin? Wouldn't this be an exploitable vulnerability?
Yes! I remember seeing "coffee orders" that had been saved from other users.
I also remember long ago having an app that allowed students to insert "comments" and I later discovered it being used as a chat channel by some non-Wellesley people!
- Could you explain the difference between .get and .getItem?
Glad to.
.getis the name chosen by the CoffeeRun designers for a method that gets data from a data store. The LocalStore has the same method, but it gets the data from the browser's local storage feature..getItemis a method for the browser-based feature.There are layers here. I'll draw a picture.
- Could you also explain this function in detail? I don't quite understand why we only need to access the keys and not t
he values:
function showDictionary(dic) { let keys = Object.keys(dic); keys.map(k => console.log(k, '=>', dic[k])); }It does access the values! That's what
dic[k]does. Theconsole.logprints both the key and the value. You could do the following instead:The original function really should use
forEachand notmap. That's an error.