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 - JavaScript Tutorial
From the course: JavaScript: Patterns
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.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
What are structural patterns?55s
-
(Locked)
Module pattern5m 54s
-
(Locked)
Mixins pattern4m 32s
-
(Locked)
Facade pattern1m 43s
-
(Locked)
Flyweight pattern1m 18s
-
(Locked)
Decorator pattern2m 16s
-
Model-View-Controller (MVC) pattern1m 21s
-
Model-View-Presenter (MVP) pattern1m 17s
-
(Locked)
Model-View-ViewModel (MVVM) pattern1m 25s
-
(Locked)
-
-