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

Tanabata romantic date without overtime, RPA robot helps you get the job done

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

营销建议 | 您有一份八月营销月历待查收! 建议收藏 !

高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer

电竞、便捷、高效、安全,盘点OriginOS功能的关键词

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

STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)

IDEA performs the Test operation, resulting in duplicate data when data is inserted

After Keil upgrades to AC6, what changes?

MySQL advanced (twenty-seven) database index principle
随机推荐
Pycharm 常用外部工具
my journal link
Happens-before rules for threads
Tanabata romantic date without overtime, RPA robot helps you get the job done
科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
Keil升级到AC6后,到底有哪些变化?
企业的数字化转型到底是否可以买来?
NowCoderTOP35-40——持续更新ing
正则表达式replaceFirst()方法具有什么功能呢?
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
Wei Dongshan Digital Photo Frame Project Learning (6) Transplantation of tslib
dotnet OpenXML parsing PPT charts Getting started with area charts
开源一夏|OpenHarmony如何查询设备类型(eTS)
蚁剑webshell动态加密连接分析与实践
Jenkins manual (2) - software configuration
无题三
电竞、便捷、高效、安全,盘点OriginOS功能的关键词
无题十一
leetcode: 529. 扫雷游戏