2

This is a weird IE quirk. Here are the steps:

  1. Go to msn.com in Internet Explorer 8
  2. Pull up dev tools
  3. Switch Browser Mode to "IE8 Compat View"
  4. Switch Document Mode to "IE7 Standards"
  5. Switch to Script tab
  6. run the following script: true.toJSON()

it returns true. No other browser does this. It's giving me issues because it's causing the tooltip widget of jQueryUI to fail for IE because at some point it passes a boolean value of true to $.isEmptyObject(). Normally passing in true would just return true but since true now has a method associated with it (toJSON) it is returning false and breaking the widget.

I noticed there are some sites (like Google) that you can try to do the same test and true.toJSON() just breaks without returning anything. What is this weird toJSON method and how do I get rid of it?

lyoung
  • 427
  • 2
  • 11
  • You really need to support IE7? Maybe you can try `delete true.toJSON`. `true` is a boolean object – Explosion Pills Feb 22 '13 at 02:21
  • 2
    preumably this should be `delete Boolean.prototype.toJSON` - but that seems like a really bad idea. – Hamish Feb 22 '13 at 02:34
  • 3
    This appears to be specific to [msn.com](http://www.msn.com/). Try another site and you'll find most don't have it. This mean MSN defined the method themselves by extending the [`Boolean.prototype`](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Boolean/prototype). – Jonathan Lonowski Feb 22 '13 at 02:35
  • It definitely occurs on other sites like USA.gov and the site I'm working on. I don't know why. – lyoung Feb 22 '13 at 03:33
  • trying to delete it might be a good idea if it only occurs in one browser under certain settings – lyoung Feb 22 '13 at 03:35

2 Answers2

2

From the jQuery.isEmptyObject() documentation:

The argument should always be a plain JavaScript Object as other types of object (DOM elements, primitive strings/numbers, host objects) may not give consistent results across browsers.

In other words, fix the tooltip widget.

Hamish
  • 22,860
  • 8
  • 53
  • 67
  • 1
    You're right. I logged a defect for the tooltip widget. http://bugs.jqueryui.com/ticket/9110 – lyoung Feb 22 '13 at 03:34
  • I figured out that the reason for the JS error was caused by only using a subset of the jquery-ui code. – lyoung Mar 13 '14 at 20:36
0

toJSON is a method that, if defined on an object, specifies the way JSON.stringify works on it. Check out MDN for more details.

Amadan
  • 191,408
  • 23
  • 240
  • 301