Ensuring Correct Use of Mixins

Lawrence D. Spencer, Seth H. Richards · 2015

This chapter explores how mixins may be used to dry out our JavaScript by isolating common functionality, such as the maintenance of unique identifiers, into mixin objects. It shows how to create the extend function used in the sample and explains how the authors' implementation of extend differs from those provided by libraries such as jQuery and underscore. It also shows how to create a traditional mixin using test-driven development. The chapter then focuses on identifying functionality appropriate for isolation into a mixin, namely functionality that has no dependency upon the implementation of the objects into which it will be mixed. It also explains a potential pitfall of the extend methods provided by the jQuery and underscore libraries, the silent replacement of existing properties.

Read the paper · More papers on PaperTik