IE8 feature test

2 views
Skip to first unread message

Nathan Stott

unread,
Jul 6, 2010, 5:35:24 PM7/6/10
to trai...@googlegroups.com
Thanks for adding that feature test to Traits to make it work in IE8.  I have another request.  Can you please cache the result of it so that it is run only one time?  I made this modification in my own code because when testing with debugging,it is annoying if you have 'break on exception' set to encounter the feature test with exception again and again.  

This is what I did:

var SUPPORTS_DEFINEPROP = (function() {
    if ("_supportsDefineProperty" in this) { return this._supportsDefineProperty; }
    try {
      var test = {};
      Object.defineProperty(test, 'x', {get: function() { return 0; } } );
      this._supportsDefineProperty = (test.x === 0);
    } catch(e) {
      this._supportsDefineProperty = false;
    }
    
    return this._supportsDefineProperty;
  })();

Nathan Stott

unread,
Jul 6, 2010, 5:36:53 PM7/6/10
to trai...@googlegroups.com
Looking back over the code I'm not sure why this was necessary, but firebugs was indeed breaking multiple times for me in my app and this has corrected that.  It looks like the function is run immediately and the results stored though so I'm not sure what the deal is.

Tom Van Cutsem

unread,
Jul 7, 2010, 9:17:22 AM7/7/10
to trai...@googlegroups.com
Hi Nathan,

I also don't fully understand: as the naming convention indicates, SUPPORTS_DEFINEPROP is a constant: it's initialized to a constant boolean immediately when the file is loaded. So in normal operation, it will only be executed once.

My guess is that, while debugging with firebug, you are probably reloading the script often (i.e. whenever you refresh the page), and reloading the script will cause the feature test to be re-executed. I guess your trick works because your script now caches the value in a property of the global object, which probably does not get reset each time you reload the script.

While I understand that the firebug experience with this behavior is annoying, I'm not sure whether caching things in the global object is the right solution to this problem. Also, it seems that other feature tests, like 'supportsGOPD()' and 'supportsDP()' would require similar workarounds.

If anyone has advice on how other JS libraries cope with such reloading-during-debugging issues, I'd love to hear it.

Cheers,
Tom

2010/7/6 Nathan Stott <nrs...@gmail.com>

Nathan Stott

unread,
Jul 7, 2010, 9:21:18 AM7/7/10
to trai...@googlegroups.com
Tom, I am definitely not reloading the page.  My app is an all one-page JavaScript app that never reloads the page.  It is definitely being reevaluated many times for some reason.

Nathan Stott

unread,
Jul 7, 2010, 9:22:24 AM7/7/10
to trai...@googlegroups.com
Hah, I just realized when I was writing 'reevaluated' why this is happening.  The CouchApp module loader must not be caching the results of my 'require' which is basically a wrapper around eval.  That's why I'm receiving an issue...
Reply all
Reply to author
Forward
0 new messages