Skip to content Skip to sidebar Skip to footer

Why Is It A Bad Idea To Override Native Methods?

I posted a question where I was overriding push using Object.defineProperty. The original question is here. The code I was working on is on my codepen. A user left a the following

Solution 1:

One problem that I can think of is that now you have a push method that is very specific to your problem, and what if you later need the normal push method. You don't really know if this will be the case or not, but it might cause you to have to refactor your code later, to allow for both the "normal push" and the "altered push".

Another problem that I can think of, is that if you do something like this and you are not the only one working on the code, someone else might not know that push is overridden and does not follow the standard behaviour anymore.

This could cause potential issues. You might not have changed it a lot, but in case the changes you made cause an error, you might leave someone else scratching his head wondering why a (in his opinion normal) push is causing odd behaviour.

Post a Comment for "Why Is It A Bad Idea To Override Native Methods?"