DEV Community

Discussion on: Top 10 JavaScript Patterns Every Developer Likes

Collapse
 
chubas profile image
Rubén Medellín

The patterns are good. The code examples, uh, they're not.

The decorator pattern as it's shown is a really bad implementation, since you're not wrapping functionality but augmenting the results. You are calling the method cost() where you should be doing something like

Decorator(baseClass){
  orig = baseClass.cost;
  baseClass.cost = () => { return orig() + number; }
}

not call the method at the decoration moment.

I'm not going to point out the errors some othe people already pointed out