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 3430658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:13:52+00:00 2026-05-18T07:13:52+00:00

How do I make a function declared in a closure, global ? This is

  • 0

How do I make a function declared in a closure, global ? This is for a google apps script, hence no window.

There is documentation on how to use closures in google apps scripts, but the example declares an object instead of a function.
http://code.google.com/googleapps/appsscript/articles/appengine.html
var JSON = JSON || {};

// foo = function(){}
(function ()
{
    ...

    foo = function (a, b)
    {
        ...
    }

    foo.prototype =
    {
        ...
    }

    // window.foo = foo; // Not Possible
}());
  • 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-18T07:13:53+00:00Added an answer on May 18, 2026 at 7:13 am

    This should work:

    var globalFoo;
    
    (function ()
    {
        ...
    
        foo = function (a, b)
        {
            ...
        }
    
        foo.prototype =
        {
            ...
        }
    
        globalFoo = foo;
        // window.foo = foo; // Not Possible
    }());
    

    I’ve made a test in a regular html running on the browser and is works fine. Here is the example:

    var globalFoo;
    console.log("O1")
    console.log(globalFoo);
    
    (function(){
        console.log("I1")
        console.log(globalFoo);
    
        var x = 13;
    
        var foo = function() {
            console.log('foo caled ' + x);
            x++;
            return true;
        }
    
        foo();
    
        globalFoo = foo;
    
        console.log("I2")
        console.log(globalFoo); 
    })();
    
    console.log("O1")
    console.log(globalFoo);
    console.log(globalFoo());
    

    The firebug output to that is:

    O1
    undefined
    I1
    undefined
    foo caled 13
    I2
    function()
    O1
    function()
    foo caled 14
    true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to make a function (the ones I'm thinking of are
The documentation indicates that the error: option function will make available: XHR instance, a
Is there any real reason not to make a member function virtual in C++?
Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param)
I know it's simple, but I can't seem to make this work. My function
This is how I have my export function declared at the moment: extern C
I often want to make a multiline function call and reduce it down to
How do I make the below function more dynamic for example commentLink and commentContainer
I'd like to make a debug logging function with the same parameters as printf
I need to make a 2D convex hull function for a class assignment and

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.