当前位置:网站首页>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?
边栏推荐
- 欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(下)
- leetcode: 529. Minesweeper Game
- 上海控安技术成果入选市经信委《2021年上海市网络安全产业创新攻关成果目录》
- 为什么sys_class 里显示的很多表的 RELTABLESPACE 值为 0 ?
- matcher中find,matches,lookingAt匹配字符串的不同之处说明
- How ali cloud storage database automatically to speed up the loading speed of www.cxsdkt.cn how to set up the case?
- 阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!
- 无题十二
- Open Source Summer | How OpenHarmony Query Device Type (eTS)
- ffmpeg drawtext 添加文本水印
猜你喜欢

Advanced usage of C language

入门 Polkadot 平行链开发,看这一篇就够了

MySQL advanced (twenty-seven) database index principle

leetcode: 529. 扫雷游戏

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

mysql进阶(二十七)数据库索引原理

Example of Noise Calculation for Amplifier OPA855

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

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

MySQL事务
随机推荐
创建一个 Dapp,为什么要选择波卡?
Egg framework usage (1)
韦东山 数码相框 项目学习(六)tslib的移植
seata源码解析:TM RM 客户端的初始化过程
What is CRM Decision Analysis Management?
七夕浪漫约会不加班,RPA机器人帮你搞定工作
[强网杯2022]WP-UM
Concurrent CAS
Voice conversion相关语音数据集综合汇总
企业的数字化转型到底是否可以买来?
19. Server-side session technology Session
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
matcher中find,matches,lookingAt匹配字符串的不同之处说明
21 Days of Deep Learning - Convolutional Neural Networks (CNN): Weather Recognition (Day 5)
阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!
After Keil upgrades to AC6, what changes?
MySQL advanced (twenty-seven) database index principle
mysql索引
公众号如何运维?公众号运维专业团队
电竞、便捷、高效、安全,盘点OriginOS功能的关键词