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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:36:19+00:00 2026-06-06T15:36:19+00:00

The original Code: ‘use strict’; function GitJs(config) { var defaults = { inheriting: false,

  • 0

The original Code:

'use strict';
function GitJs(config) {
    var defaults = {
        inheriting: false,
        clientId: undefined,
        accessToken: undefined,
        baseUrl: 'https://api.github.com',
        mode: 'read'
    };

    this.config = $.extend(defaults, config);
}

/**
 * Gets the jQuery method that GitJs#generateApiRequest is going to use to send the ajax request.
 *
 * @param {string} httpVerb The HTTP verb that the request will use,
 * @return string
 */
GitJs.prototype.getCommandMethod = function (httpVerb) {
    var method = $.get;

    switch (httpVerb) {
    case 'GET':
        method = $.get;
        break;
    case 'POST':
        method = $.post;
        break;
    }
    return method;
};

...

The new code:

(function() {
'use strict';
    'use strict';
    function GitJs(config) {
        var defaults = {
            inheriting: false,
            clientId: undefined,
            accessToken: undefined,
            baseUrl: 'https://api.github.com',
            mode: 'read'
        };

        this.config = $.extend(defaults, config);
    }

    /**
     * Gets the jQuery method that GitJs#generateApiRequest is going to use to send the ajax request.
     *
     * @param {string} httpVerb The HTTP verb that the request will use,
     * @return string
     */
    GitJs.prototype.getCommandMethod = function (httpVerb) {
        var method = $.get;

        switch (httpVerb) {
        case 'GET':
            method = $.get;
            break;
        case 'POST':
            method = $.post;
            break;
        }
        return method;
    };

    ...
}());

As this code stands, when I attempt:

var gitjs = new GitJs();

I am told that GitJs is undefined

What the hell I was thinking:

  • I don’t want to put use strict inside of every method.
  • I want my code to play nice if it gets minified and concatenated to another file.
  • I want to use the .prototype syntax for ease of inheritance later on (and code clarity)
  • I don’t want to make a global var gitJs variable because it could be overridden by someone else’s script.
  • I assume that the user will always invoke the object constructor via the new keyword

For the record, I know I’m wrong. Way wrong. I just can’t seem to figure out where the flaw in my thinking lies and I’d love some guidance.

  • 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-06T15:36:20+00:00Added an answer on June 6, 2026 at 3:36 pm

    Your problem is that GitJS is now a private variable of the immediately invoked function. You can’t hide your function in a private scope and make it publicly available at the same time. They are mutually exclusive goals.

    Therefore, you will want to either explicitely set the global variable, via the window

    var GitJS;
    (function() {
        'use strict';
         GitJS = function(){ ... }
         ...
    }());
    

    or return the exported function from inside the IIFE.

    var ExportedGitJS = (function(){ //using a different name just to be clear...
        'use strict';
        var GitJS = function(){ ... }
        ...
        return GitJS;
    }());
    

    OK, I lied. You can make Javascript modules without having to rely on global variables but that usualy means also using a different module-creation convention and/or using a module library. I would highly recommend that you check out http://requirejs.org/ if you are interested in this.

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

Sidebar

Related Questions

---Original code---- $(function () { var options = { xaxis: { mode: time, tickLength:
I need to migrate some C# code to Python. The original code makes use
Original code: (can be seen working here: http://sandbox.hokuten.net/jqrpg/ ) /* google.setOnLoadCallback(function() { */ $(function()
The original code: this.control.addEventListener('click', $.proxy(function() { this.time.hashours = (this.duration() / 3600) >= 1.0; this.time.duration.text(getTime(this.duration(),
Here is the original code: if (($handle = fopen($source_file, r)) !== FALSE) { $columns
The original code looks like this,it works. def my_index(request): global account if request.session.get('account',False): account=request.session['account']
Trying to make this function dynamic instead of static. This was the original code
i have a mistake in my code ) Fatal error: Call to undefined function
The original code was somehow complex, i simplify it as: Given: list of class
The original code: public List<Contact> GetContactListEntityCompiledLINQ() { if (entities == null) entities = new

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.