1

After modified Object.prototype, all of jQuery's methods running on selectors started resulting in the below error:

Uncaught TypeError: matchExpr[type].exec is not a function

And also when I call $.post(). it says that $.post() is not undifined.

What I did was:

Object.prototype.extend = function(object) {
      ...
   }

What am I missing here?

user11615054
  • 25
  • 1
  • 4

1 Answers1

2

Rule #1: Avoid Monkey Patching at all costs!

Overriding methods of built-in Objects (via the prototype property, as in your example) is a major anti-pattern and it's considered a really, really bad practice!

You just need to think of another way to accomplish what you are trying to achieve, without overriding these methods.

You might want to take a look at jQuery's extend method for example.

Reference

Why is extending native objects a bad practice

Kostas Minaidis
  • 4,681
  • 3
  • 17
  • 25