On Sep 25, 2009, at 3:22 PM, David Flanagan wrote:

Charles Jolley wrote:
Has anyone considered providing a more explicit way of testing for this? Maybe a constant that is defined somewhere.

Strict mode isn't a global on-or-off thing. Some functions can be strict while others aren't. So you can't capture it in a constant.

Good point -- I was thinking of the useful fact to capture that the browser supports strict mode (more below).


Anyway, that's what I'm going to do:
SC.HAS_STRICT = !(function() { return this;}());
:)

If you're testing "does this browser support strict mode" then you'd better test it in an explicitly strict context:

SC.HAS_STRICT = (function() {
 "use strict";
  return !(function() { return this; }());
}());

(Or something like that. I sure will be happy when there's an implementation to test this stuff against.)

You don't need two levels of functions. I just spaced out on the "use strict"; in the anonymous function that returns |this|:

if (! function(){"use strict"; return this;}()) { /* strict mode supported by the browser */ }


Otherwise, what you're testing for is something like "is this code currently running in strict mode" or "was this library loaded under strict mode"?

Thanks for wiping up after me. :-)

/be

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to