Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5849003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:56:20+00:00 2026-05-22T12:56:20+00:00

I don’t find anything about my question here on MDC or the ECMAscript specifications.

  • 0

I don’t find anything about my question here on MDC or the ECMAscript specifications. Probably somebody knows a more ‘hacky’ way to solve this.

I’m calling "use strict" on every javascript file in my environment. All my files start like this

(function(win, doc, undef) {
    "use strict";

    // code & functions
}(window, window.document));

Now, I have a custom function which handles errors. That functions uses the .caller property to provide a context stack trace. Looks like this:

var chain = (function() {
    var _parent = _error,
        _ret = '';

    while( _parent.caller ) {
        _ret += ' -> ' + _parent.caller.name;
        _parent = _parent.caller;
    }

    return _ret;
}());

But of course, in strict mode .caller is a non-deletable prop which throws when retrieved. So my question is, is anybody aware of way to disable strict more “function-wise” ?

"use strict"; is inherited by all functions after it was called. Now we have the possibilty to just use strict mode in specific functions by just calling "use strict"; at the top of those, but is there a way to achieve the opposite ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:56:20+00:00Added an answer on May 22, 2026 at 12:56 pm

    No, you can’t disable strict mode per function.

    It’s important to understand that strict mode works lexically; meaning — it affects function declaration, not execution. Any function declared within strict code becomes a strict function itself. But not any function called from within strict code is necessarily strict:

    (function(sloppy) {
      "use strict";
    
       function strict() {
         // this function is strict, as it is _declared_ within strict code
       }
    
       strict();
       sloppy();
    
    })(sloppy);
    
    function sloppy(){
      // this function is not strict as it is _declared outside_ of strict code
    }
    

    Notice how we can define function outside of strict code and then pass it into the function that’s strict.

    You can do something similar in your example — have an object with “sloppy” functions, then pass that object to that strict immediately invoked function. Of course, that won’t work if “sloppy” functions need to reference variables from within main wrapper function.

    Also note that indirect eval — suggested by someone else — won’t really help here. All it does is execute code in global context. If you try to call a function that’s defined locally, indirect eval won’t even find it:

    (function(){
      "use strict";
    
      function whichDoesSomethingNaughty(){ /* ... */ }
    
      // ReferenceError as function is not globally accessible
      // and indirect eval obviously tries to "find" it in global scope
      (1,eval)('whichDoesSomethingNaughty')();
    
    })();
    

    This confusion about global eval probably comes from the fact that global eval can be used to get access to global object from within strict mode (which isn’t simply accessible via this anymore):

    (function(){
      "use strict";
    
      this; // undefined
      (1,eval)('this'); // global object
    })();
    

    But back to the question…

    You can kind of cheat and declare a new function via Function constructor — which happens to not inherit strictness, but that would rely on (non-standard) function decompilation and you would lose ability to reference outer variables.

    (function(){
      "use strict";
    
      function strict(){ /* ... */ }
    
      // compile new function from the string representation of another one
      var sneaky = Function('return (' + strict + ')()');
    
      sneaky();
    })();
    

    Note that FF4+ seems to disagree with spec (from what I can tell) and incorrectly marks function created via Function as strict. This doesn’t happen in other strict-mode-supporting implementations (like Chrome 12+, IE10, WebKit).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand where the extra bits are coming from in this article about
Don't let below code scare you away . The question is really simple, only
I don't know when to add to a dataset a tableadapter or a query
I don't edit CSS very often, and almost every time I need to go
I don't want PHP errors to display /html, but I want them to display
I don’t think I’ve grokked currying yet. I understand what it does, and how
I don't remember whether I was dreaming or not but I seem to recall
I don't expect a straightforward silver bullet answer to this, but what are the
I don't want to take the time to learn Obj-C. I've spent 7+ years
I don't know if anyone has seen this issue before but I'm just stumped.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.