4

What's the best method to check if the protoype of a method has been changed?

Geuis
  • 41,122
  • 56
  • 157
  • 219

1 Answers1

3

It depends on what you mean by "changed" if you mean changed between when your code gets loaded and some later time, you can just store a reference to the function, a la

var oldFunc = SomeType.prototype.someFunction;
...
if (oldFunc === someInstance.someFunction) // unchanged, note the use of strict equality

But if you mean changed from the default native implementation there's no real way to tell.

olliej
  • 35,755
  • 9
  • 58
  • 55
  • So some libraries like Prototype modify the core object prototypes, like Array.prototype.push or pop. So I'm wondering how you can check if the default prototype method for a native object has been changed. – Geuis Feb 22 '09 at 10:19
  • @Geuis did you ever figure out a way to check if the default prototype method for a native object has been changed? – Stiofán May 18 '21 at 06:41
  • @Stiofán I hope you realize that question was from over *12* years ago. I have no idea what the context was when I asked that originally. Today we have the constructor pattern with getter and setters. You might be able to do something with those. – Geuis May 19 '21 at 07:59