Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/tips/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class SomeClass {
这些 Decorator 也是基于 `Reflect Metadata` 实现,这次,我们将 `metadataKey` 定义在 `descriptor` 的 `value` 上:

```ts
const METHOD_METADATA = 'method'
const PATH_METADATA = 'path'
const METHOD_METADATA = 'method';
const PATH_METADATA = 'path';

const Controller = (path: string): ClassDecorator => {
return target => {
Expand All @@ -168,13 +168,13 @@ function mapRoute(instance: Object) {

// 筛选出类的 methodName
const methodsNames = Object.getOwnPropertyNames(prototype)
.filter(item => !isConstructor(item) && isFunction(prototype[item]))
.filter(item => !isConstructor(prototype[item]) && isFunction(prototype[item]));
return methodsNames.map(methodName => {
const fn = prototype[methodName];

// 取出定义的 metadata
const route = Reflect.getMetadata(PATH_METADATA, fn);
const method = Reflect.getMetadata(METHOD_METADATA, fn)
const method = Reflect.getMetadata(METHOD_METADATA, fn);
return {
route,
method,
Expand Down