当前位置:网站首页>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);
};
边栏推荐
- Example of Noise Calculation for Amplifier OPA855
- 欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(上)
- IO stream articles -- based on io stream to realize folder copy (copy subfolders and files in subfolders) full of dry goods
- Oracle临时表空间作用
- Handwriting Currying - toString Comprehension
- tensorflow.keras cannot introduce layers
- First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
- [Unity] [UGUI] [Display text on the screen]
- 【Unity】【UGUI】【在屏幕上显示文本】
- Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g
猜你喜欢
Redis源码解析:Redis Cluster
Custom filters and interceptors implement ThreadLocal thread closure
如何实现按键的短按、长按检测?
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
Oracle临时表空间作用
Concurrent CAS
深度学习21天——卷积神经网络(CNN):天气识别(第5天)
IDEA执行Test操作导致数据插入时出现了重复数据
Seata source code analysis: initialization process of TM RM client
2.4G无线收发模块的应用
随机推荐
seata源码解析:TM RM 客户端的初始化过程
ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...
MySQL advanced (twenty-seven) database index principle
干货!生成模型的评价与诊断
uniapp 连接ibeacon
JS逆向入门学习之回收商网,手机号码简易加密解析
PAT Class B-B1019 Digital Black Hole (20)
PAT Level B - B1021 Single Digit Statistics (15)
无题九
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
手写柯里化 - toString 理解
Pytorch Deep Learning Quick Start Tutorial -- Mound Tutorial Notes (3)
The Seven Weapons of Programmers
NowCoderTOP35-40 - continuous update ing
PAT乙级-B1019 数字黑洞(20)
Assembly language (8) x86 inline assembly
放大器OPA855的噪声计算实例
PAT Grade B-B1020 Mooncake(25)
Four years of weight loss record
Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)