arguments.callee in Harmony

Mark S. Miller erights at google.com
Fri Sep 25 21:01:50 PDT 2009


On Fri, Sep 25, 2009 at 2:24 PM, Charles Jolley <charles at sproutit.com> wrote:
> PS. Is there an official way to detect that I am running code in ES5 strict mode?  I can't find it in the spec.

To summarize:

A conventional pattern for testing "Am I in >= ES5 strict mode?" is

    if (function(){return this;}()) {
      // I am not in strict mode
    } else {
      // I am in strict mode, and therefore in >= ES5
    }

A conventional pattern for testing "Am I in >= ES5?" is

    if (function(){"use strict";return this;}()) {
      // I am in < ES5
    } else {
      // I am in >= ES5
    }

For these to work, it is important that browser makers rolling out ES5
features incrementally not cause the ES5-sides of these tests to
succeed until their ES5 system is complete. In other words, much as it
pains me to suggest this, please implement strict mode last.


-- 
    Cheers,
    --MarkM


More information about the es-discuss mailing list