It doesn't. There's no connection.
OOP is how we happen to implement the code that dynamically creates the HTML/CSS on the page, but we could have done it in other ways.
To the extent that HTML and CSS are code, we are writing JS code that writes HTML/CSS code.
code that writes code is tricky!
var order1 = {emailAddress: key1, coffee: "black with milk and an embarrassing amount of sugar", size: "short", flavor: "mocha", strength: 38 };why size, flavor, strength are not in a string format? Thank you!
Unlike Python, JS requires keys to be strings, and it will automatically stringify the keys, so you don't have to type the string quotes. Consider:
The extra string quotes around x
are unnecessary in JS, unlike Python.
Probably, but not always.
Sometimes, the user will submit data in a known format and we will look for particular things (keys), such as emailAddress
, in which case the code might be obj.emailAddress
.
Sometimes, the code is generic and doesn't know what the set of keys are, so it may iterate over them. Like this:
Or it might have the key be an argument as with our KeyValueDB
class or Coffeerun's DataStore
class
In the generic situation, when the key is contained in a variable, we have to use the square bracket notation.
Yes. An API is a general notion of code interacting with other code.
Take something simple like a built-in object, say dictionaries, lists or strings.
They have an API: a set of methods that they support, etc., allowing us to use them.
We don't know how dictionaries, lists and strings are implemented, and they might be implemented differently in different browsers. But as long as they correctly implement the API, it all works. That's the abstraction barrier
A class is a way of defining a new kind of object and part of that definition is its API.
In general, yes, we have to import code in order to use it. (Unless it's built-in, see above.)
The API is the set of rules of how we use it once it's imported: the functions and methods that we just imported.
Yes. If you're able to modify the code of a module that other people import, you can do nefarious things.
Some things are imported dynamically (e.g. jQuery from a CDN). An attack there gets propagated very quickly.
Some things are imported sporatically (e.g. jQuery downloaded and stored locally)
The constructor is a function that is invoked when we say new Classname(constructor_args...)
.
It can give initial values to the instance variables.
Instance variables are how we store data in an object, like the coordinates of the point p1
above.
Yes, that will work.
Differs from what? It is different from all the other classes.
Its purpose is to store the set of pending orders for a particular "food truck". In principle, we could have several.
It has methods like createOrder
, deliverOrder
and printOrders