当前位置:网站首页>js hijacks the array push method
js hijacks the array push method
2022-08-05 10:01:00 【Jedi Hongbin】
const withVolume = [];
withVolume.push = function (...items) {
console.log(items);
return Array.prototype.push.call(this, ...items);
};
If you use the pointed function
withVolume.push = (...items) => {
console.log(items);
return Array.prototype.push.call(withVolume, ...items);
};
在ts中使用
interface MonitorArray<T> extends Array<T> {
monitoringChanges?: (...items: T[]) => void;
}
const withVolume: MonitorArray<Object3D> = [];
withVolume.push = (...items: typeof withVolume[number][]) => {
if (typeof withVolume.monitoringChanges === "function") withVolume.monitoringChanges(...items);
return Array.prototype.push.call(withVolume, ...items);
};
withVolume.monitoringChanges = (...items: typeof withVolume[number][]) => {
console.log("change :", ...items);
};
构造函数修改
interface MonitorArray<T> extends Array<T> {
constructor:{
prototype:{
monitoringChanges?: (...items: T[]) => void;
}
}
}
withVolume.constructor.prototype.monitoringChanges = (...items: typeof withVolume[number][]) => {
console.log("change :", ...items);
};
JavaScriptHow to monitor array changes
proxy的理解及proxyWhy can monitor arrays?
边栏推荐
- Bias lock/light lock/heavy lock lock is healthier. How is locking and unlocking accomplished?
- Four years of weight loss record
- 21 Days of Deep Learning - Convolutional Neural Networks (CNN): Weather Recognition (Day 5)
- 茄子科技CEO仇俊:以用户为中心,做用户真正需要的产品
- 【zeno】为zeno增加子模块/新节点的最小化的例子
- 科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
- 【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
- 轩辕实验室丨欧盟EVITA项目预研 第一章(四)
- Analysis and practice of antjian webshell dynamic encrypted connection
- 无题三
猜你喜欢

IDEA执行Test操作导致数据插入时出现了重复数据

shell脚本实例

阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!

What is CRM Decision Analysis Management?

自定义过滤器和拦截器实现ThreadLocal线程封闭

The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf

Dry goods!Generative Model Evaluation and Diagnosis

C语言的高级用法

eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑

Custom filters and interceptors implement ThreadLocal thread closure
随机推荐
基于MindSpore高效完成图像分割,实现Dice!
什么是CRM决策分析管理?
express hot-reload
Voice conversion相关语音数据集综合汇总
Can MySQL use aggregate functions without GROUP BY?
Example of Noise Calculation for Amplifier OPA855
CPU的亲缘性affinity
seata源码解析:TM RM 客户端的初始化过程
如何实现按键的短按、长按检测?
Marketing Suggestions | You have an August marketing calendar to check! Suggest a collection!
无题十四
Advanced usage of C language
21 Days of Deep Learning - Convolutional Neural Networks (CNN): Clothing Image Classification (Day 3)
[强网杯2022]WP-UM
mysql索引
2022-08-01 Review the basic binary tree and operations
mysql进阶(二十七)数据库索引原理
What is the function of the regular expression replaceFirst() method?
MySQL事务
长达四年的减肥记录