Advanced Data Structures
With the ES2015 version of the JavaScript specification came several new data structures like Map, Set, WeakMap, WeakSet and Proxy. We’ll look at the motivations for adding these features to the language and get hands-on experience solving some problems that would be much more difficult were it not for these new constructs.
-
Advanced Data StructuresMaps and Sets
Map
andSet
are new data structures that have distinct advantages in various use cases. We’ll study both in detail, including their “weak” counterparts:WeakMap
andWeakSet
. -
Advanced Data StructuresPROJECT: Spies and Stubs
Using a
Map
, we’ll build a small “spying” library that we can use to monitor function invocations in our tests. -
Advanced Data StructuresProxies
Proxy
can “wrap” JavaScript objects or functions, potentially intercepting or modifying certain behaviors along the way. -
Advanced Data StructuresPROJECT: Buffered Proxy
Although there aren’t many obvious use cases for the
Proxy
type, one place where it proves handy is to “stage” proposed modifications to an object, without mutating the underlying values directly. We’ll implement a “buffered proxy” utility, and use it in an “edit form” context. -
Advanced Data StructuresWrap up and Recap
We'll recap everything we've covered today, and set our sights on tomorrow's agenda.