当前位置:网站首页>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?
边栏推荐
- 电竞、便捷、高效、安全,盘点OriginOS功能的关键词
- The Seven Weapons of Programmers
- NowCoderTOP35-40——持续更新ing
- Tanabata romantic date without overtime, RPA robot helps you get the job done
- What is CRM Decision Analysis Management?
- 轩辕实验室丨欧盟EVITA项目预研 第一章(四)
- leetcode: 529. Minesweeper Game
- IDEA执行Test操作导致数据插入时出现了重复数据
- 高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer
- matcher中find,matches,lookingAt匹配字符串的不同之处说明
猜你喜欢
dotnet OpenXML 解析 PPT 图表 面积图入门
Open Source Summer | How OpenHarmony Query Device Type (eTS)
NowCoderTOP35-40——持续更新ing
three.js调试工具dat.gui使用
MySQL advanced (twenty-seven) database index principle
5.部署web项目到云服务器
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
Marketing Suggestions | You have an August marketing calendar to check! Suggest a collection!
Analysis and practice of antjian webshell dynamic encrypted connection
随机推荐
如何实现按键的短按、长按检测?
Can MySQL use aggregate functions without GROUP BY?
MySQL advanced (twenty-seven) database index principle
matcher中find,matches,lookingAt匹配字符串的不同之处说明
开发常用手册链接分享
three物体围绕一周呈球形排列
19. Server-side session technology Session
告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
Dry goods!Generative Model Evaluation and Diagnosis
七夕浪漫约会不加班,RPA机器人帮你搞定工作
入门 Polkadot 平行链开发,看这一篇就够了
Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)
【Unity】【UGUI】【在屏幕上显示文本】
2022-08-01 Review the basic binary tree and operations
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
5. Deploy the web project to the cloud server
js劫持数组push方法
Happens-before rules for threads
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
egg框架使用(一)