📜  将方法附加到 javascript 代码示例中已存在的类

📅  最后修改于: 2022-03-11 15:02:12.646000             🧑  作者: Mango

代码示例1
Array.prototype.newMethod = function() {}
/* - Replace "Array" with your Class name - 

 Typing the name of your Class in the console
 won't show the newly added method.
Only by appending .prototype to the class name
you will see the new method appended to the class, in its definition.

The technique is also called Monkey Patching and is
NOT recommended, for the reasons outlined in the source link*/