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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:41:31+00:00 2026-06-10T05:41:31+00:00

For example: // a.js goog.provide(‘mypackage.a’); goog.provide(‘mypackage.commands’); mypackage.a.somevar = 1; mypackage.commands.save = function(…) {…}; //

  • 0

For example:

// a.js
goog.provide('mypackage.a');
goog.provide('mypackage.commands');

mypackage.a.somevar = 1;

mypackage.commands.save = function(...) {...};

// b.js
goog.provide('mypackage.b');
goog.provide('mypackage.commands');

mypackage.b.somevar = 1;

mypackage.commands.read = function(...) {...};

// mypackage/commands.js
goog.provide('mypackage.commands');

mypackage.commands.runCommand = function(commandText, args) {
  return mypackage.commands[commandText](args);
}

Is this a good way to provide an extensible set of commands, or is there something that could make this complex that I’m not thinking about?

  • 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-10T05:41:33+00:00Added an answer on June 10, 2026 at 5:41 am

    There is no reason that you can’t or shouldn’t provide the same module in different source files. If it makes sense to your source code organization scheme, then it’s a perfectly fine thing to do. One of the main reasons that we have goog.provide() is so that the same symbol can be used in several different places, but defined in whichever file happens to run first.

    If I understand goog.provide() correctly, all it does is make sure that an object is declared. So, goog.provide(‘mypackage.commands) makes sure thatmypackage.commands` is declared in the global scope.

    So goog.provide('mypackage.commands'); just accomplishes something similar to this:

    window.mypackage = window.mypackage || {};
    window.mypackage.commands = window.mypackage.commands || {};
    

    You only need to do that when you plan on adding things to that object in this source file. So, if multiple source files are all adding new items onto mypackage.commands, then each source file would do goog.provide('mypackage.commands)` to make sure that the right global variable structure is declared.

    That appears to be what you are doing in your code example and that is a perfectly fine thing to do. It is up to your own sense of code organization whether it’s better to have multiple source files all contributing to the same object (like you have) or whether you should organize your source files such that all code pertaining to one particular namespace is in the same file. That’s really up to you and how you think it is best to organize your source code – there is no right or wrong answer other than there should be some rhyme and reason behind how it’s organized.

    Helpful reference article: https://developers.google.com/closure/library/docs/tutorial

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

Sidebar

Related Questions

Example: var sessions = require('sessions'); function load_session(req) { sessions.load(sid); } Now that the session
Example class code: <?php class example { public function forExample() { return true; }
Example of function: call getThings(amount, place, limit, marginError) SYNOPSIS: CALL getThings(4, PA, 3, 1.2);
Example 1 : function a(){ return ok; } function b(){ this.c = a; }
The example below shows a class that extends a goog.ui.Component. Should the properties of
Example Div: <div class=container> <div class=select1></div> <div class=select2></div> <div class=select3></div> </div> Now I want
Example: print max(chain_length(i) for i in xrange(1,10001)) This returns the maximum/biggest chain_length (an arbitrary
Example: $ objdump Logger.cpp.o -t 00000000 g F .text 00000000 .hidden __sti___10_Logger_cpp_0b2ae32b
Example: copy in one tmux pane (via vim), then switch to another pane (running
Example: an Employee table with an optional DateOfBirth field can be normalized into two

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.