当前位置:网站首页>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
Seata source code analysis: initialization process of TM RM client
PAT乙级-B1020 月饼(25)
Brief Analysis of WSGI Protocol
Hundred lines of code launch red hearts, why programmers lose their girlfriends!
PHP operation mangoDb
2.4G无线收发模块的应用
shell脚本实例
mysql进阶(二十七)数据库索引原理
Handwriting Currying - toString Comprehension
干货!生成模型的评价与诊断
Microservice Technology Stack
创建一个 Dapp,为什么要选择波卡?
Why do I recommend using smart async?
手写柯里化 - toString 理解
EU | Horizon 2020 ENSEMBLE: D2.13 SOTIF Safety Concept (Part 2)
放大器OPA855的噪声计算实例
hcip BGP 增强实验
C语言的高级用法
Is there a problem with writing this?How to synchronize data in sql-client