当前位置:网站首页>Typescript使用修饰器混合方法到类
Typescript使用修饰器混合方法到类
2022-07-29 18:45:00 【RemoteDev】
mixins.ts
//导出混合方法
export function mix(...args){
return function (t){
Object.assign(t.prototype,...args);//添加方法到对象原型
}
}
test_mixins.ts
import { mix} from './mixins';//导入混合方法
//声明要混合入类的方法
let methodToMix = {
MixFunc(){console.log('this method use for Mix');}
}
@mix(methodToMix)//在类声明中使用了修饰器@mix
class MyClass{}
let obj = new MyClass();//实例化类,类对象具有修饰器混入的方法MixFunc
obj.MixFunc();//调用混入的方法
测试结果 :
边栏推荐
- 第01章 Linux下MySQL的安装与使用【1.MySQL架构篇】【MySQL高级】
- The backslash \\ in MySQL is really a pit
- Setting right:0 after sticky positioning does not take effect
- 低代码三部曲之未来
- 测试基础:Nosql数据库之Redis
- 高速无源链路阻抗匹配套路
- Answer these 3 interview questions correctly, and the salary will go up by 20K
- word文档里插入图片显示不完整,只显示一半,怎么处理?
- sticky定位后设置right:0不生效
- 500强企业研发效能提升课,今晚开课啦!
猜你喜欢
随机推荐
【中标麒麟系统Your trial is EXPIRED and no VALID licens 关闭弹窗】
云商店专访 | 云速ERP,小场景里帮企业做“大生意”
新博客
夏令营课程复习资料汇总
transformer通俗理解
KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!
项目分析(三个小众的嵌入式产品)
AI全流程开发难题破解之钥
function arguments
2.5w字 + 36 张图爆肝操作系统面试题 学不吐你
Really touch the fish and lead the teacher: The programmer brother works 10 minutes a day with an annual salary of 570,000. I broke the defense...
swin-transformer初步理解
High-speed passive link impedance matching routine
迅为i.MX8MM开发板Coatrx-M4内核开发给IAR安装8MM补丁
Low code of the trilogy
UG安装出现Server Start Failed. The Server May Already Be Running!!解决方法
C pitfalls and pitfalls
Word Embedding与Word2Vec学习
测试基础:Nosql数据库之Redis
Postgresql-xl全局快照代码走读与GTM原理(支线1)