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.

3
  • I'm not getting any black background or exceptions after closing the modal in that JSFiddle. Commented Jun 8, 2012 at 19:44
  • I should have been more specific. You have to uncomment the second Object.prototype... line. Also, the error will only show in the console. Commented Jun 8, 2012 at 19:54
  • And by console I mean, the Chrome/Firefox dev console. Commented Jun 8, 2012 at 19:55

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much for the link -- I did not realize that this was a convention required by jQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.