Skip to content

Commit

Permalink
feat: decorator docs
Browse files Browse the repository at this point in the history
  • Loading branch information
javaswing committed Aug 23, 2023
1 parent 17c5fbb commit 86d29cf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions code/ES6/Decorator/index.ts
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.');
}
}
6 changes: 6 additions & 0 deletions code/ES6/Decorator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"target": "ES5",
"experimentalDecorators": true
}
}
21 changes: 21 additions & 0 deletions docs/zh/guide/ES6/Decorator.mdx
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

0 comments on commit 86d29cf

Please sign in to comment.