Urara-Blog/urara/2022-08-06-notes/+page.md
2025-03-22 17:04:42 +08:00

21 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Monkey Patch
created: 2022-08-06
summary: 猴子打补丁
toc: false
tag:
- Notes
---
[Monkey Patch - Wikipedia](https://en.wikipedia.org/wiki/Monkey%20patch)
> A **Monkey patch** is a way for a program to extend or modify supporting system software locally (affecting only the running instance of the program)."
也可以可以理解为基于原生功能API的一些自定义拓展这个概念常在 Python 里面出现,也叫鸭子双关
[Checking if a JavaScript native function is monkey patched](https://mmazzarolo.com/blog/2022-07-30-checking-if-a-javascript-native-function-was-monkey-patched/)
> Monkey patching is a powerful but dangerous technique because the code youre overriding is not in your control: future updates to the JavaScript engine may break some assumptions made in your patch and cause serious bugs.
> Additionally, by monkey patching code you dont own, you might override some code that has already been monkey patched by another developer, introducing a potential conflict.
对于 JS 来说Monkey patch 的问题在于:如果 JS 引擎更新了,可能会带来一些难以预计的 bug这篇文章说了几种怎么检测是否存在 monkey patch 函数的方法,比如用 toString、iframe、proxy 等等,但都不是很完美,可以根据使用场景来决定用哪种方法