当前位置:网站首页>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);
};
边栏推荐
猜你喜欢

CPU的亲缘性affinity

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

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

Weekly Report 2022-8-4

shell脚本实例

Overall design and implementation of Kubernetes-based microservice project

eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑

Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?

什么是CRM决策分析管理?

hcip BGP enhancement experiment
随机推荐
QSS 选择器
PHP 操作mangoDb
无题六
Handwriting Currying - toString Comprehension
歌词整理
Analysis and practice of antjian webshell dynamic encrypted connection
偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑
hcip BGP enhancement experiment
数据中台建设(十):数据安全管理
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
语音社交软件开发——充分发挥其价值
Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
express hot-reload
Bias lock/light lock/heavy lock lock is healthier. How is locking and unlocking accomplished?
无题九
【Unity】【UGUI】【在屏幕上显示文本】
长达四年的减肥记录
Voice conversion相关语音数据集综合汇总
轩辕实验室丨欧盟EVITA项目预研 第一章(四)