From the course: JavaScript: Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Decorator pattern

Decorator pattern - JavaScript Tutorial

From the course: JavaScript: Patterns

Start my 1-month free trial

Decorator pattern

- The decorator pattern is very similar to mixins, where we decorate code with classes or code that came from another area. There is actual syntax in the most recent versions of JavaScript and has been used for a while in TypeScript and is heavily used in Angular code. So the purpose of a decorator pattern, like a mixin, is to to take, for example, a class and extended it with other code. Because we've already done extends and mixin's let's see an example code on TypeScripts website how it would be implemented. The syntax will be similar in JavaScript once it is officially approved for use in a recent version of JavaScript. So go to typescripeline.org/docs look for handbook and then scroll down until you see decorators. And then on that page scroll down until you see this example here. So this is a great example of decorator. So it looks very similar to mixin. So you're basically creating a function which is called F.…

Contents