课程: JavaScript: Patterns

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Decorator pattern

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.…

内容