-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Person { | ||
name: string; | ||
|
||
constructor(name: string) { | ||
this.name = name; | ||
} | ||
|
||
greet() { | ||
console.log('LOG: Entering method.'); | ||
|
||
console.log(`Hello, my name is ${this.name}.`); | ||
|
||
console.log('LOG: Exiting method.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES5", | ||
"experimentalDecorators": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Decorator 详解 | ||
|
||
装饰器,这类东西我最早接触是在Java中的`Annotation`这个东西,使用起来很方便、优雅。可以减少很多冗余的代码。 | ||
|
||
## 介绍 | ||
装饰器(Decorator)主要是用来增强JavaScript类(class)的功能,请多的面向对象语言都在类似的东西。 | ||
比如:Java中的[`Annotation`](https://www.cnblogs.com/ziph/p/13056092.html)、C#中的[`Attribute`](https://www.cnblogs.com/zuiyirenjian/p/3980608.html)等。 | ||
|
||
注:目前的使用场景主要在`TypeScript`中使用。演示代码主要在为ts代码. | ||
|
||
## 语法 | ||
|
||
|
||
|
||
## 参考 | ||
|
||
1. https://es6.ruanyifeng.com/#docs/decorator | ||
2. https://caniuse.com/decorators | ||
3. https://www.typescriptlang.org/docs/handbook/decorators.html | ||
4. https://github.com/tc39/proposal-decorators | ||
5. https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#decorators |