当前位置:网站首页>js劫持数组push方法
js劫持数组push方法
2022-08-05 09:54:00 【Jedi Hongbin】
const withVolume = [];
withVolume.push = function (...items) {
console.log(items);
return Array.prototype.push.call(this, ...items);
};
如果使用尖头函数
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);
};
边栏推荐
- 正则表达式replaceAll()方法具有什么功能呢?
- How to realize the short press and long press detection of the button?
- 只有一台交换机,如何实现主从自动切换之nqa
- First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
- 无题八
- ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...
- Jenkins manual (2) - software configuration
- Seata source code analysis: initialization process of TM RM client
- PAT Class B-B1019 Digital Black Hole (20)
- 语音社交软件开发——充分发挥其价值
猜你喜欢

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

Hundred lines of code launch red hearts, why programmers lose their girlfriends!

首次去中心化抢劫?近2亿美元损失:跨链桥Nomad 被攻击事件分析

Advanced usage of C language

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

leetcode: 529. 扫雷游戏

开源一夏|OpenHarmony如何查询设备类型(eTS)

express hot-reload

MySQL内部函数介绍

Redis源码解析:Redis Cluster
随机推荐
欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(上)
电竞、便捷、高效、安全,盘点OriginOS功能的关键词
CCVR eases heterogeneous federated learning based on classifier calibration
Excuse me, guys, is it impossible to synchronize two databases in real time using Flink SQL CDC?
无题十一
Handwriting Currying - toString Comprehension
PAT乙级-B1019 数字黑洞(20)
openpyxl to manipulate Excel files
my journal link
Concurrent CAS
深度学习21天——卷积神经网络(CNN):天气识别(第5天)
5. Deploy the web project to the cloud server
PHP operation mangoDb
Oracle temporary table space role
轩辕实验室丨欧盟EVITA项目预研 第一章(四)
新白娘子传奇系列
微服务 技术栈
19.服务器端会话技术Session
歌词整理
Custom filters and interceptors implement ThreadLocal thread closure