4

I have a very weird issue.

I'm using Twitter Bootstrap 2. I have a modal dialogue on a page, which I am opening like this:

$('#rights-dialogue).modal();

I am also adding a custom function to the Object.prototype object, like this:

Object.prototype.foo = function (a) {};

When the x button in the modal dialogue is clicked, the dialogue closes, but the black background remains and I get a strange jQuery error in the jQuery event handling code:

Uncaught TypeError: Cannot read property 'origType' of undefined

If I remove all arguments from my foo() function, I do not not get this error, and everything works fine.

Here is a jsfiddle that illustrates the issue: http://jsfiddle.net/nicholascloud/r6T8z/5/.

I have no idea what's going on here.


EDIT: A few other things I've noticed.

It doesn't seem to matter what the name of the method is on Object.prototype. Any method with arguments will cause this error. If a method is added with no arguments, the error does not occur.

The error occurs when jQuery detaches the event listener keyup.dismiss.modal from the DOM.

I have confirmed this error with jQuery 1.7.1 and 1.7.2, but my suspicion is that its a Twitter Bootstrap problem and not jQuery per se.

Nicholas Cloud
  • 1,564
  • 1
  • 13
  • 19

1 Answers1

5

This has to do with jQuery and extending Object.prototype.

See this question: Prototyping Object in Javascript breaks jQuery?

Essentially, you should avoid extending Object.prototype, but see the answer for more details.

Community
  • 1
  • 1
Jason Capriotti
  • 1,836
  • 2
  • 17
  • 33