当前位置:网站首页>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);
};
边栏推荐
- CPU的亲缘性affinity
- dotnet OpenXML 解析 PPT 图表 面积图入门
- 入门 Polkadot 平行链开发,看这一篇就够了
- 新白娘子传奇系列
- Excuse me if you want to write data in mysql, with flink - connector - JDBC directly is ok, but I'm in the f
- Oracle临时表空间作用
- IO流篇 -- 基于io流实现文件夹拷贝(拷贝子文件夹及子文件夹内文件)满满的干货
- 创建一个 Dapp,为什么要选择波卡?
- The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf
- 2022-08-01 回顾基础二叉树以及操作
猜你喜欢

egg框架使用(二)

Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g

js 图形操作一(兼容pc、移动端实现 draggable属性 拖放效果)

Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)

There is only one switch, how to realize the nqa of master-slave automatic switching

21 Days of Deep Learning - Convolutional Neural Networks (CNN): Weather Recognition (Day 5)

Keil升级到AC6后,到底有哪些变化?

Microservice Technology Stack

How to realize the short press and long press detection of the button?

hcip BGP 增强实验
随机推荐
仿SBUS与串口数据固定转换
dotnet OpenXML parsing PPT charts Getting started with area charts
Oracle temporary table space role
无题十三
首次去中心化抢劫?近2亿美元损失:跨链桥Nomad 被攻击事件分析
leetcode 剑指 Offer 10- II. 青蛙跳台阶问题
Why do I recommend using smart async?
leetcode: 529. Minesweeper Game
openpyxl to manipulate Excel files
IDEA performs the Test operation, resulting in duplicate data when data is inserted
放大器OPA855的噪声计算实例
Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g
Brief Analysis of WSGI Protocol
mysql索引
韦东山 数码相框 项目学习(六)tslib的移植
js 图形操作一(兼容pc、移动端实现 draggable属性 拖放效果)
Redis源码解析:Redis Cluster
Open Source Summer | How OpenHarmony Query Device Type (eTS)
电竞、便捷、高效、安全,盘点OriginOS功能的关键词
PAT Class B-B1019 Digital Black Hole (20)