Dorothy Parker is known less for her work on the original ‘A Star is Born’ screenplay and more for her unbeatable quips e.g., “This wasn’t just plain terrible, this was fancy terrible, with raisins in it.”
A function is a set of statements that performs a task, like calculating a value, that can be repeated. They’re foundational to all the interactions we might have on a website.
We started out covering basics, like a few different ways to write and format functions, including with arrows (=> fancy). We also covered arrays, derived from functions, and a few of their methods. Methods are, unsurprisingly, just fancy functions attached to Objects that can do useful things like .push() new items into a data set. We manipulated array indices to find unique items, in our use case specific interns or cars.
We got to work with 5k runners instead in our next data set, which I’ve been ready for since St. Patrick’s day. We used that data to apply what we learned about closures, the invisible glue that lets child (embedded) functions reference values in parent functions, and higher order functions that can take in other functions called callbacks as parameters. We also covered more complex array methods like .reduce() that returns a value from the array, or .map() that creates a new array.
After adding that complexity, we deep-dived on the
this keyword and how it points functions to the right context to find a value. We covered constructor functions for creating new Objects of a certain type a little less manually, and their prototypes, which we use to add methods to each new Object. We used those concepts to build different Heroes and Villains in a very basic game.
Of course, we learned a much easier way to create new Objects immediately the next day with Classes, which embed constructor functions and use keywords like ‘extends’ and super() to ensure attributes and methods can be inherited by a new Class. We refactored the previous day’s code to be more palatable with these new tools.
While tiring, learning something the hard way first can be worthwhile, so that we then understand why the shortcuts under the hood work, or, in other words, what the fancy raisins are doing in there in the first place.