Discuz! Board

 找回密碼
 立即註冊
搜索
熱搜: 活動 交友 discuz
查看: 153|回復: 0

Property Keyit

[複製鏈接]

1

主題

1

帖子

5

積分

新手上路

Rank: 1

積分
5
發表於 2023-12-21 17:09:48 | 顯示全部樓層 |閱讀模式
At the time of publishing this article according to the TC repository decorators are still in the candidate phase stage . If you want to use decorators in TypeScript simply enable them using the configuration option experimentalDecorators. You can pass it on transpilation or add the key with the value truein the tsconfig.

Once you enable decorators you can now use them as described in the TypeScript documentation . Below you will find a practical example of a simple Handler whose handle method has been decorated with a method that logs Phone Number List the input data. function logParams return function target unknown propertyKey string sed parameters that allow obtaining information from where the decorator was called.




In the example presented targetit is an object of the class Handler  is the name of the decorated method and descriptorit is an instance of the property descriptor of the method handle. Note especially that the decorator returns a function that will be called at the time of decorating. Everything above the return keyword will be called before the handle method is decorated. Take a look at the example below and see in what order each message is logged.



回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|小黑屋|DiscuzX

GMT+8, 2024-11-19 00:25 , Processed in 0.026663 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回復 返回頂部 返回列表