当前位置:网站首页>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?
边栏推荐
猜你喜欢
华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
Two-table query average grouping in sql server
dotnet OpenXML 解析 PPT 图表 面积图入门
【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样
MySQL内部函数介绍
dotnet OpenXML parsing PPT charts Getting started with area charts
数据中台建设(十):数据安全管理
three.js调试工具dat.gui使用
IDEA performs the Test operation, resulting in duplicate data when data is inserted
js 图形操作一(兼容pc、移动端实现 draggable属性 拖放效果)
随机推荐
Seata source code analysis: initialization process of TM RM client
[强网杯2022]WP-UM
技术干货 | 基于 MindSpore 实现图像分割之豪斯多夫距离
公众号如何运维?公众号运维专业团队
NowCoderTOP35-40 - continuous update ing
无题一
5. Deploy the web project to the cloud server
Example of Noise Calculation for Amplifier OPA855
First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
seata源码解析:TM RM 客户端的初始化过程
无题二
哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?
仿SBUS与串口数据固定转换
Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g
Jenkins manual (2) - software configuration
Microservice Technology Stack
Marketing Suggestions | You have an August marketing calendar to check! Suggest a collection!
2.4G无线收发模块的应用
mysql索引