Classes
The controversy around class stems from the illusion of removing prototypal inheritance from JavaScript. It is, in fact, just syntactic sugar on top of the same prototypes we’ve been using all along. However, in removing some of the noise that typically accompanies object-oriented JavaScript, and in making some typical traps more difficult to fall into, using classes can result in more readable and robust code.
-
ClassesWelcome
We'll recap everything we've covered so far, and review the day's agenda.
-
ClassesClasses in JavaScript
While
class
doesn’t allow us to do anything that wasn’t possible with the direct use of prototypes, many things are easier and much cleaner. We’ll look at constructors, member and static functions, and the upcoming “member and instance field” TC39 proposals. -
ClassesEXERCISE: Colors with classes
We’ll look back at our rgb/hex color exercises, and implement a more comprehensive solution using classes.
-
ClassesDecorators
Decorators allow us to do things at class construction time. Several uses of decorators are possible with the current draft spec (or when using Typescript) and a variety of proposals for new decorators are already in development!
-
ClassesPROJECT: Memoized functions
Memoization is a technique that can be used with pure functions, where output values are “remembered” for an input argument(s). Thus, re-invoking the function with the same arguments will return the same “remembered” result. We’ll implement a
@memoize
function decorator, so that we can apply this technique easily and cleanly in our code. -
ClassesInheritance Patterns
While it's true that
class
is only syntactic sugar on top of JavaScript’s prototypal inheritance, the new syntax makes it easier and cleaner to implement things like "mixins". We'll select a few important design patterns from the famous "Gang of Four" design patterns book and implement them using classes. -
ClassesPROJECT: Design Patterns w/ Class
We’ll implement some examples of classical object-oriented design patterns using
class
. -
ClassesLunch
Break for lunch