HTML and CSS Reference
arguments. Finally, because the cache key is generated by joining the parameters
with a comma, string arguments that contain commas can cause the wrong value to
be loaded, i.e., (1, "b") would generate the same cache key as ("1,b") .
It is possible to implement a proper serializer that can embed type information
about arguments, and possibly use tddjs.uid to serialize object and function
arguments, but doing so would impact the performance of memoize in a noticeable
way such that it would only help out in cases that could presumably be better
optimized in other ways. Besides, serializing object arguments using tddjs.uid ,
although simple and fast, would cause the method to possibly assign new properties
to arguments. That would be unexpected in most cases and should at the very least
be properly documented.
In this chapter we have worked through a handful of practical function examples
with a special focus on closures. With an understanding of the scope chain from
Chapter 5, Functions, we have seen how inner functions can keep private state in
free variables. Through examples we have seen how to make use of the scope and
state offered by closures to solve a range of problems in an elegant way.
Some of the functions developed in this chapter will make appearances in
upcoming chapters as we build on top of them and add more useful interfaces to
the tddjs object. Throughout the topic we will also meet plenty more examples
of using closures.
ter understanding of how property access and prototypal inheritance work, how
different ways to create objects and share behavior between them.