当前位置:网站首页>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?
边栏推荐
- three物体围绕一周呈球形排列
- Pytorch Deep Learning Quick Start Tutorial -- Mound Tutorial Notes (3)
- 自定义过滤器和拦截器实现ThreadLocal线程封闭
- 19. Server-side session technology Session
- Four years of weight loss record
- 【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
- 静态链接和动态链接
- Advanced usage of C language
- 仿SBUS与串口数据固定转换
- ffmpeg drawtext add text watermark
猜你喜欢

告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来

What is CRM Decision Analysis Management?

营销建议 | 您有一份八月营销月历待查收! 建议收藏 !

【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样

蚁剑webshell动态加密连接分析与实践

七夕浪漫约会不加班,RPA机器人帮你搞定工作

Keil升级到AC6后,到底有哪些变化?

mysql索引

dotnet OpenXML 解析 PPT 图表 面积图入门

Custom filters and interceptors implement ThreadLocal thread closure
随机推荐
QSS 选择器
无题九
ffmpeg drawtext add text watermark
MySQL使用聚合函数可以不搭配GROUP BY分组吗?
dotnet OpenXML 解析 PPT 图表 面积图入门
Microservice Technology Stack
项目成本控制如何帮助项目成功?
The difference between find, matches, lookingAt matching strings in matcher
What is the function of the regular expression replaceAll() method?
静态链接和动态链接
HStreamDB Newsletter 2022-07|分区模型优化、数据集成框架进一步完善
无题十三
Egg framework usage (1)
PAT乙级-B1021 个位数统计(15)
Dry goods!Generative Model Evaluation and Diagnosis
Concurrent CAS
three物体围绕一周呈球形排列
长达四年的减肥记录
Bias lock/light lock/heavy lock lock is healthier. How is locking and unlocking accomplished?
七夕浪漫约会不加班,RPA机器人帮你搞定工作