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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:16:48+00:00 2026-06-16T06:16:48+00:00

I have my own custom Javascript object, defined as follows: function NewObject(){ this.fetchConfig(); }

  • 0

I have my own custom Javascript object, defined as follows:

function NewObject(){
   this.fetchConfig();
}

NewObject.prototype.fetchConfig = function(params){
    [Code]
}

I’ve omitted the actual implementation for brevity, but I do nothing special other than the above. The issue is, when I actually embed the script similar to the way Google Analytics is embedded (see below), I get Uncaught TypeError: Object #<NewObject> has no method 'fetchConfig'.

I never saw this issue before I used the Async code below, which is essentially Google’s modified to point to my script instead of Google Analytics.

The embed code I use:

<script>_object_id = 19782135;
    var tb = document.createElement('script'); tb.type = 'text/javascript';
    tb.async = true; tb.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cfurl.cloudfront.net/script.min.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(tb, s);
</script>

Could this issue be caused by using the async property (e.g. the script is executed before the prototype has been modified)? I tried using the web debugger and inspecting the prototype of the NewObject, but I only see the constructor– none of the other methods I wrote appear in the debugger at all…

  • 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-16T06:16:49+00:00Added an answer on June 16, 2026 at 6:16 am

    Now I see your error clearly with your complete code.

    In JavaScript, how you write your code is not the way how the parser actually reads it. It is read according to a certain order which is summarized in 3 groups:

    1. variable declarations
    2. function declarations
    3. All others, according to the order they appear in the scope. This includes

      • operations (function calls, conditionals, loops etc.)
      • variable assignments (variables, function expressions, prototype assignments)
      • everything else I missed

    For example, this code:

    new foo();
    function foo(){...}
    foo.prototype.bar = function(){...};
    var bar = 'baz';
    

    actually looks like this to the parser:

    var bar;                          //variable declaration
    function foo(){...};              //function declaration
                                      //operations and assignments
    new foo();                        //this is foo, but no bar yet
    foo.prototype.bar = function(){}; //function expressions (prototype assignment)
    bar = 'baz';                      //variable assignment
    

    You can test the following code to see how the variable is undefined instead of at console.log() even when in the code, the declaration comes after it. It’s because the declaration is “hoisted up” but not the assignment. So it sees the variable, but not the value. A comparison is made with a non-existent variable to see the difference:

    console.log('ndefined is:',ndefined);     //undefined, sees the variable
    console.log('notDefined is:',notDefined); //not defined, non-existent variable
    var ndefined = 'I should be defined!!!';
    

    Now in your code, this code:

    if (_object_id) {...new NewObject(_object_id)...}
    
    function NewObject(params) {...return this.fetchConfig(params)...}
    
    NewObject.prototype.fetchConfig = function (id) {}
    

    appears like this to the parser due to the order which it parses:

    //priority 2: function declarations
    //function declarations are "hoisted up"
    function NewObject(params) {...return this.fetchConfig(params)...}
    
    //priority 3: assignments and operations
    //at this point, fetchConfig is not yet in the prototype
    //yet your constructor uses it, hence the error
    if (_object_id) {...new NewObject(_object_id)...}
    
    NewObject.prototype.fetchConfig = function (id) {}
    

    In short, the if statement saw your constructor because it was hoisted up. But the constructor never had fetchConfig by that time. To fix this, change the order:

    function NewObject(params) {...return this.fetchConfig(params)...}
    
    if (_object_id) {...new NewObject(_object_id)...}
    
    NewObject.prototype.fetchConfig = function (id) {}
    

    The best practice would be to declare stuff or operate on them the way the parser does it. This also means formatting your code in that manner. This way, it will clear up some confusion regarding the code.

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

Sidebar

Related Questions

I have this custom function to calculate MD5 hash, written in Java. I can't
I have my own custom webpart. Inside this webpart I would like to display
Javascript - The Definitive Guide (6ed) shows the following code: Originally we have this
I have a code for jqGrid with custom editFunc that opens my own jQuery-UI
I have my own custom Content Provider that loads a database which contains the
We have our own custom calendar in our portal which is developed in Java.
I have my own custom tool for Visual Studio 2008 SP1. It consists of
I have my own custom UISegmentedControl subclass. It's buttons are bigger than the standard
I would like to have my own custom change_password page and I am already
I have an XML layout and want to add my own custom SurfaceView to

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.