当前位置:网站首页>Typescript mix method to class with decorator
Typescript mix method to class with decorator
2022-07-29 20:02:00 【RemoteDev】
mixins.ts
//Export mixed methodexport function mix(...args){return function (t){Object.assign(t.prototype,...args);//Add method to object prototype}}test_mixins.ts
import { mix} from './mixins';//Import mixed method//declare the method to be mixed into the classlet methodToMix = {MixFunc(){console.log('this method use for Mix');}}@mix(methodToMix)//The decorator @mix is used in the class declarationclass MyClass{}let obj = new MyClass();//Instantiate the class, the class object has the method MixFunc that the decorator is mixed inobj.MixFunc();//Call the mixed methodTest Results:

边栏推荐
猜你喜欢

Small application components

PX4模块设计之十四:Event设计

What should I do if the Win11 network is unstable?The solution to frequent disconnection of wifi connection in Win11

算力顶天地,存力纳乾坤:国家超级计算济南中心的一体两面
pfSense高可用(HA)功能介绍

谈谈如何建立价值驱动的数据战略

高速无源链路阻抗匹配套路

c语言 || 杂

Answer these 3 interview questions correctly, and the salary will go up by 20K

function arguments
随机推荐
实现一个可调节大小的 Switch 开关
Answer these 3 interview questions correctly, and the salary will go up by 20K
低代码三部曲之未来
无人驾驶与人工驾驶的对比,人工驾驶的优缺点
MySQL筑基篇之增删改查
FP6601QS6 SOT-23-6 USB专用充电端口控制器 QC2.0/3.0快充协议IC
[数学]必备基本知识
for key in object 遍历对象遇到的问题
R语言时间序列数据提取:使用xts包的last函数提取时间序列中最后面两周的数据(last 2 week)
新王加冕还是动物乐园?7大顶级蓝筹NFT项目详解
The backslash \\ in MySQL is really a pit
function arguments
在宇宙中心五道口上班,是怎样一种体验
c语言 || 杂
如何防止订单重复支付?
答对这3个面试问题,薪资直涨20K
QT 如何计算中英文字符串的长度
数字孪生万物可视 | 联接现实世界与数字空间
etcd实现大规模服务治理应用实战
智能合约安全——重入漏洞