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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:37:54+00:00 2026-06-14T10:37:54+00:00

I have noticed that Google Chrome debugger behaves quite differently depending on how a

  • 0

I have noticed that Google Chrome debugger behaves quite differently depending on how a JS object is created;

If I create an js object like this;

var SonA = function(thename) {
               this.firstname = thename || "Graham";
               this.age = 31;
}

SonA.prototype = new Father();

Then Chrome’s debugger doesn’t allow me to drill down and view the prototype. It does however give me key value pairs of the instance variables name and age.

However, if I omit the this keyword, I am able to drill down to the prototype, but I do not get the instance variables displayed in the debugger.

//SonB doesn't use this keyword    
var SonB = function(thename) {
                  firstname = thename || "Graham";
                  age = 31;
           } 

SonB.prototype = new Father();
console.log(new SonA()); //this logs as: SonA {firstname: "graham", age: 31}
console.log(new SonB()); //this logs as as drill down object that shows the prototype

Does anyone know what is going on here, and why the behavior of the debugger is different? The following image and jsfiddle may make the issue clearer to understand;

Screenshot

http://jsfiddle.net/7z8sp/1/

  • 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-14T10:37:55+00:00Added an answer on June 14, 2026 at 10:37 am

    I don’t see what it is you’re trying to achieve. The only reason why you can “drill down” to the prototype in sonB, is because the constructor isn’t setting any properties, but it’s creating implied globals. Just add this line to your fiddle:

    console.log(age);//<--logs 31
    

    It logs the values that are being set by the sonB constructor. If you want to get at the prototype-properties, you either: delete the child’s property, or you use the Object.getPrototypeOf() method.

    To clarify: this isn’t inherent to the debugger, but to the way JS gets the values and properties of an object. consider the following:

    var emptyObject = {};
    console.log(emptyObject.someProperty);//logs undefined
    Object.prototype.someProperty = 'YaY';
    console.log(emptyObject.someProperty);//logs YaY
    emptyObject.someProperty = function()
    {
        return Object.getPrototypeOf(this).someProperty;
    };
    console.log(typeof emptyObject.someProperty);//function
    console.log(emptyObject.someProperty());//YaY again
    delete(emptyObject.someProperty);//returns true
    console.log(emptyObject.someProperty);//logs YaY.
    

    What does this mean: simply put, if you attempt to access a property on any object (arrays, objects, functions, the lot) JS will first check if that particular instance has that property defined, if it doesn’t, then JS steps up a level in the prototype-chain. If that prototype doesn’t have the requested property, JS skips to the next prototype, and so on. If no property was found, undefined will be returned.
    It therefore stands to reason that, if your constructor sets certain properties, JS won’t bother with the prototypes and return the properties ASAP.

    The same logic applies to implied globals. If variables are missing the var keyword, JS scans the scopes (current function, “parent” function(s), and eventually the global scope) in search of that variable. If it is found, that variable will be either used or reassigned (depending on what you’re doing with it in your code). If no variable was found, then JS will kindly create one for you. Sadly, without bothering to return to the current scope. The result: a global variable is created.
    In your code, the Father constructor, creates a new function object for each instance. This unction relies on a closure variable (sirname) and a global variable (firstname). The latter isn’t being set by SonA, because that constructor assigns a new property. SonB, however, does create the global variable that both SonA and SonB will share.

    The only reason why the getName member function of Father is working on sonB, is because that method, too, relies on scope-scanning and an implied global:

    new SonB();//<-- constructor sets age and firstname globals
    SonB.getName();//<-- ~= Father.getName.apply(SonB,arguments);
         ||
         ---> gets firstname global that was set in SonB constructor, uses that value
    

    That’s all there is too it, just redefine Father’s getName method to:

    this.getName = function()
    {//use this to point at calling context -> IE the instance on which the member function is being invoked
        return this.firstname + ' ' + surname;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this webpage which shows several brand logos. I noticed that Google Chrome
I have recently noticed, that in some versions of Google Chrome the classic css-only
I have noticed that Google Toolbox for Mac replaces several SQLite built-in functions (LOWER/UPPER,
I have noticed that when you view PDFs in google docs the PDF viewer
I have noticed that doing actions like implementing an interface, that a small rectangle
I have created an application that read messages with voice. I would like to
I am a Google Maps API (JavaScript) developer. I have noticed that Google uses
I have noticed that, from Google Maps page, you can get an embed link
I've been using Google Chrome for a while now and I noticed that it
I have noticed that some json queries, particularly in google services, return a peculiar

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.