当前位置:网站首页>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?
边栏推荐
- 2022-08-01 回顾基础二叉树以及操作
- 华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
- ffmpeg drawtext add text watermark
- What is the function of the regular expression replaceFirst() method?
- uniapp 连接ibeacon
- 无题十一
- 哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?
- Open Source Summer | How OpenHarmony Query Device Type (eTS)
- 偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
- Egg framework usage (2)
猜你喜欢

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

js graphics operation one (compatible with pc, mobile terminal to achieve draggable attribute drag and drop effect)

DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从

欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(上)

How to realize the short press and long press detection of the button?

three.js调试工具dat.gui使用

MySQL事务

数据中台建设(十):数据安全管理

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

Egg framework usage (2)
随机推荐
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
入门 Polkadot 平行链开发,看这一篇就够了
自定义过滤器和拦截器实现ThreadLocal线程封闭
How ali cloud storage database automatically to speed up the loading speed of www.cxsdkt.cn how to set up the case?
企业的数字化转型到底是否可以买来?
egg框架使用(一)
NowCoderTOP35-40——持续更新ing
dotnet OpenXML 解析 PPT 图表 面积图入门
Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
2022.8.3
PAT Level B - B1021 Single Digit Statistics (15)
Voice conversion相关语音数据集综合汇总
无题五
Open Source Summer | How OpenHarmony Query Device Type (eTS)
长达四年的减肥记录
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
你最隐秘的性格在哪?
仿SBUS与串口数据固定转换
Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)
干货!生成模型的评价与诊断