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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:24:01+00:00 2026-06-12T07:24:01+00:00

Where can I read documentation concerning the execution order rules for GS files? To

  • 0

Where can I read documentation concerning the execution order rules for GS files?

To dimension the problem I created two trivial objects, each in their own file.

1_File.gs

var ObjB = new Object();
ObjB.sayName = "[" + ObjA.sayName + "]";

0_File.gs

var ObjA = new Object();
ObjA.sayName = " I'm A ";

A call such as …

Logger.log(ObjA.sayName + " : " + ObjB.sayName);

… gets the error …

TypeError: Cannot read property "sayName" from undefined.

If I move the code from 1_File.gs into 0_File.gs, and vice versa, then there is no error and the log shows correctly …

I’m A : [ I’m A ]

Renaming 0_File.gs to 2_File.gs doesn’t affect execution order either, so I assume that order depends on which file gets created first.

Is there no concept of “include” or “import” that would allow me to make order of execution explicit?

  • 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-06-12T07:24:02+00:00Added an answer on June 12, 2026 at 7:24 am

    Where can I read documentation concerning the execution order rules for GS files?

    There is no such documentation and I think will not be any time published. In similar way, an initialization order of the static variables in C++ is also undefined and depends on compiler/linker.

    Is there no concept of “include” or “import” that would allow me to make order of execution explicit?

    Yes, there is no “includes”, “imports” and even “modules”, but there are libraries.

    Also there is a workaround by using a closure. Bellow is a sample code. By executing the test function the log contains c.d. The idea is to have in all gs files a function started with init. In these functions all global variables are instanced. The anonymous closure is executed during the Code.gs file instancing and calls all “init” functions of all gs files.

    Code.gs

    var c;
    
    function callAllInits_() {
      var keys = Object.keys(this);
      for (var i = 0; i < keys.length; i++) {
        var funcName = keys[i];
        if (funcName.indexOf("init") == 0) {
          this[funcName].call(this);
        }
      }
    }
    
    (function() {
      callAllInits_();
      c = { value : 'c.' + d.value };
    })();
    
    function test() {
      Logger.log(c.value);
    }
    

    d.gs

    var d;
    
    function initD() {
      d = { value : 'd' };
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Android documentation concerning code signing we can read: By signing multiple applications with
I've read through the Oracle documentation concerning the CONNECT operations, but I can't seem
Where can I read the SpecFlow documentation that tells me about the [BeforeScenario] and
I have read the documentation and searched all over but I can't find how
Do I read the NSHTTPCookieStorage documentation right that you can't delete other cookies than
I have read the FactoryGirl documentation, but I can't seem to figure this out.
I have read in the Apple Documentation that we can use optional parameters in
I've read through the SASS documentation and can only find how to do a
I have read that in Java interfaces can't be instantiated ( in the documentation,
I've read about hydration in doctrine's documentation but I still can't understand what it

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.