Elements of Reusable Object-Oriented Software. From Journeyman to Master.
This is for the folks that made it through Crockford's The Good Parts knowing that they learned something but also feeling less-than-certain about how to apply that something.
This is not a Bad Thing; sometimes it pays to see information presented again--to help it sink in or else to gain another perspective on it. Sometimes and I've written this before you were just hoping for The book could have taken another quick editorial pass for spelling and grammar. The one that stuck out at me was right in the intro to Chapter 6: An in-depth overview, but an overview nonetheless.
Stefanov is careful to "keep the browser out of it" and dedicates only one chapter Chapter 8: DOM and Browser Patterns to the subject; though everyone's favorite host environment does creep in a couple of times, in a couple of examples. View all 3 comments. Dec 23, Adrian Li rated it really liked it.
Don't force yourself to go through absolutely everything, and definitely skip some sections if it's quite obvious that you won't really need to go through them in detail since a lot of today's best practices avoid some of the mentioned patterns completely. Nevertheless, this is an important book to read. And if you have a nuanced reading strategy like I mentioned above , you can probably get through this book within 3 hours or so and learn a decent amount while doing so.
Feb 28, Greenicicle rated it liked it Shelves: So far I'm a little disappointed that practices like "write sensible comments" and "indent properly" are really listed as patterns, especially when the book claims to be targeted to professional devs. But I've still got a bunch of pages to go through. The title does not lie: There is a focus on organizational patterns object creation, inhheritance. Of these, there is a large variety of variants; mostly presented in an evolutionary chain the le So far I'm a little disappointed that practices like "write sensible comments" and "indent properly" are really listed as patterns, especially when the book claims to be targeted to professional devs.
One example is using an office printer. After reviewing the Module , Prototype , Observer , and Singleton design patterns, you should be able to identify these patterns and use them in the wild. Since we are returning an object, we will prefix the prototype object with a function. How to write a great review. We appreciate your feedback. The four stars comes mostly from two niggling points: This event system allows code to define application-specific events that can pass custom arguments containing values needed by the subscriber.
One of the many advantages of classes is encapsulation - protecting states and behaviors from being accessed from other classes. The module pattern allows for public and private plus the lesser-know protected and privileged access levels. Modules should be Immediately-Invoked-Function-Expressions IIFE to allow for private scopes - that is, a closure that protect variables and methods however, it will return an object instead of a function. This is what it looks like:. Code outside of our closure is unable to access these private variables since it is not in the same scope.
Let's take a more concrete implementation:. However, when outside the module, contents are unable to be referenced. A variation of the module pattern is called the Revealing Module Pattern. The purpose is to maintain encapsulation and reveal certain variables and methods returned in an object literal. The direct implementation looks like this:. Although this looks much cleaner, an obvious disadvantage is unable to reference the private methods.
Prototype Design Pattern on Wikipedia.
To clone an object, a constructor must exist to instantiate the first object. Next, by using the keyword prototype variables and methods bind to the object's structure. Let's look at a basic example:. The constructor allows the creation of a single TeslaModelS object.
When a creating new TeslaModelS object, it will retain the states initialized in the constructor. Additionally, maintaining the function go and stop is easy since we declared them with prototype. A synonymous way to extend functions on the prototype as described below:.