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

边栏推荐
- 无人驾驶与人工驾驶的对比,人工驾驶的优缺点
- OpenCV - 图像二值化处理 腐蚀膨胀 边缘检测 轮廓识别
- c语言 || 杂
- 从零在AutoDL调试一份目标检测代码
- MySQL筑基篇之增删改查
- R语言ggplot2可视化绘制条形图(bar plot)、使用gghighlight包突出高亮条形图中的特定条形(highlight specific bar plot)
- 7 lines of code crashed station B for 3 hours, but because of "a tricky 0"
- 算力顶天地,存力纳乾坤:国家超级计算济南中心的一体两面
- pfSense高可用(HA)功能介绍
- 每日优鲜“坠落”,生鲜前置仓的面子和里子
猜你喜欢
随机推荐
从零在AutoDL调试一份目标检测代码
OpenCV - 图像二值化处理 腐蚀膨胀 边缘检测 轮廓识别
etcd实现大规模服务治理应用实战
Setting right:0 after sticky positioning does not take effect
支持向量机SVM
五种常见IO模型
QT 如何计算中英文字符串的长度
Canal实现Mysql数据增量同步更新至Mysql/Redis
R语言ggplot2可视化绘制条形图(bar plot)、使用gghighlight包突出高亮条形图中的特定条形(highlight specific bar plot)
智能合约安全——重入漏洞
【win10系统安装deepin双系统重启进不了win系统解决办法】
测试基础:Nosql数据库之Redis
FPGA设计8位十进制计数器异步/同步模块以及m序列码产生器模块
数字孪生万物可视 | 联接现实世界与数字空间
【APP 改进建议】希望增加 pdf 及 word 的导出能力
大疆MID 360
Chengdu | Changed to software testing, from zero income to over 10,000 monthly salary, a new turning point in life...
小程序组件的总结
Working for 9 years!
【PyCharm 常用快捷键】








