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

  • SEARCH
  • Home
  • 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 6468997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:56:32+00:00 2026-05-25T05:56:32+00:00

So I saw a function that was, quite frankly beautiful in its simplicity as

  • 0

So I saw a function that was, quite frankly beautiful in its simplicity as it allowed you to find the global object ( which depending on environ at the time may NOT have been window ) while within an anonymous function; however when you throw javascripts’ “use strict”; mode it crumbles, due to the evaluation of the keyword ‘this’ changing. There were a few ways to accomplish this?

(function () {
    var win = function () {
        return (function () {
                return this;
            }());
        };
    //win now points to the global object no matter where it is called.
}());

Now, if these are called within the context of “use strict” we lose the functionality described, is there any equivalent that can be done in ES5 strict mode?

For reference

(function () {
    "use strict"
    //code here is in strict mode
}())
  • 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-25T05:56:33+00:00Added an answer on May 25, 2026 at 5:56 am

    Access to the Global Object (before ES5)

    If you need to access the global object without hard-coding the identifier window, you can do the following from any level of nested function scope:

    var global = (function () {
        return this;
    }());
    

    This way you can always get the global object, because inside functions that were invoked
    as functions (that is, not as constrictors with new) this should always point to
    the global object.

    This is actually no longer the case in ECMAScript 5 in strict mode,
    so you have to adopt a different pattern when your code is in strict mode.

    For example,
    if you’re developing a library, you can wrap your library code in an immediate function
    (discussed in Chapter 4) and then from the global scope, pass a reference to this as a
    parameter to your immediate function.

    Access to the Global Object (after ES5)

    Commonly, the global object is passed as an argument to the immediate function so
    that it’s accessible inside of the function without having to use window: this way makes
    the code more interoperable in environments outside the browser:

    (function (global) {
        // access the global object via `global`
    }(this));
    

    “JavaScript Patterns, by Stoyan Stefanov
    (O’Reilly). Copyright 2010 Yahoo!, Inc., 9780596806750.”

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

Sidebar

Related Questions

I saw a java function that looked something like this- public static<T> foo() {...}
Now I have a function that has to return a string. I saw a
I'm learning C and I saw in a book that a function prototype has
Today I saw a JavaScript syntax (when invoking a function) that is unfamiliar to
When I read some question to write random nuber generator ,I saw that function
I saw the function below that should return sign of double d. But I
What is a generic list manipulation function in C? (I saw this when I
I saw this same question for VIM and it has been something that I
I want to build a Python function that calculates, and would like to name
What is convention for local vars that has same meaning as function argument? If

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.