当前位置:网站首页>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:

边栏推荐
- Answer these 3 interview questions correctly, and the salary will go up by 20K
- 优雅实现经典的生产者消费者模式
- 谈谈如何建立价值驱动的数据战略
- 小程序组件的总结
- C pitfalls and pitfalls
- Chapter 02 MySQL Data Directory [1. MySQL Architecture] [MySQL Advanced]
- sticky定位后设置right:0不生效
- OpenCV - 图像二值化处理 腐蚀膨胀 边缘检测 轮廓识别
- R语言时间序列数据提取:使用head函数或者tail函数获取时间序列数据中最早或者最新的样本数据
- Small application components
猜你喜欢
随机推荐
自定义组件-behaviors
支持向量机SVM
工作9年了!
H264码流RTP封装方式详解
大疆MID 360
第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
R语言时间序列数据提取:使用xts包的first函数提取时间序列中最前面两周的数据(first 2 week)
总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对
KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!
String类型_static成员_动态内存分配_拷贝构造函数_const关键字_友元函数与友元类
Idea工具的使用
不用Swagger,那我用啥?
R语言时间序列数据提取:使用head函数或者tail函数获取时间序列数据中最早或者最新的样本数据
知识库对企业的意义
2.5w字 + 36 张图爆肝操作系统面试题 学不吐你
如何防止订单重复支付?
What should I do if the Win11 network is unstable?The solution to frequent disconnection of wifi connection in Win11
低代码三部曲之未来
软件测试面试屡屡失败,面试官总是说逻辑思维混乱,怎么办?
项目分析(三个小众的嵌入式产品)
![[数学]必备基本知识](/img/ac/f3552ef31948e1c31ce692fa87a796.png)








