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

Marketing Suggestions | You have an August marketing calendar to check! Suggest a collection!

CCVR eases heterogeneous federated learning based on classifier calibration

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

基于MindSpore高效完成图像分割,实现Dice!

干货!生成模型的评价与诊断

mysql进阶(二十七)数据库索引原理
![[强网杯2022]WP-UM](/img/3d/caeab05ddca278af274dbf6e2f8ba1.png)
[强网杯2022]WP-UM

Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need

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

Two-table query average grouping in sql server
随机推荐
MySQL使用聚合函数可以不搭配GROUP BY分组吗?
[强网杯2022]WP-UM
深度学习21天——卷积神经网络(CNN):天气识别(第5天)
2022-08-01 Review the basic binary tree and operations
哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?
无题十三
【温度预警程序de开发】事件驱动模型实例运用
使用工具类把对象中的null值转换为空字符串(集合也可以使用)
无题十
企业的数字化转型到底是否可以买来?
无题十一
uniapp 连接ibeacon
PAT乙级-B1019 数字黑洞(20)
Seata source code analysis: initialization process of TM RM client
高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer
2022.8.3
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
How ali cloud storage database automatically to speed up the loading speed of www.cxsdkt.cn how to set up the case?
长达四年的减肥记录
无题三