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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:05:22+00:00 2026-05-27T03:05:22+00:00

I am unable to understand this loop behavior of the javascript. Can someone tell

  • 0

I am unable to understand this loop behavior of the javascript.

Can someone tell me why was it designed in this way?
Is there any real use case of this behavior?

why this loop? {
Newly created instance inherits properties from the prototype property of the constructor function object.
prototype property of the constructor function is an object that keeps constructor property.
constructor property is equal to the constructor function object.
Again constructor function object keeps prototype property.
}

instance1—inhertis(keeps)–>Prototype property of func()–>keep constructor property–>function object func–>keep prototype property.

var func = function(){};
var construct = func.prototype.constructor;

console.log(construct === func); //true

var instance1 = new func();

Updated: Even if in between i assigned something else, instanceof always returns true.

var func1 = function(){};
func1.prototype.constructor = 1;

var instance1 = new func1();
console.log(instance1 instanceof func1); //true


var func2 = function(){};
func2.prototype.constructor = 0;

var instance2 = new func2();
console.log(instance2 instanceof func2); //true

Sorry to ask 2 question in 1 but both may be related.

  • 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-05-27T03:05:22+00:00Added an answer on May 27, 2026 at 3:05 am

    Of course it retains the instance. Why wouldn’t it? If you’re making a duck, it’s a duck – its DNA says that it’s a duck, no matter if you paint it black or teach it to be a goose.

    Also, in your case, setting the constructor has no effect. When you do new func (or new func(), which are identical), you go and grab an internal property of the function (the [[Construct]] property), and not func.prototype.constructor.

    obj.constructor is defined on every single object, since it’s defined on every “constructor”: That is, Object Number Function Date Boolean String and so on. Each have a constructor property in their prototype:

    Object.prototype.constructor === Object;
    String.prototype.constructor === String;
    //etc
    

    Each one has its prototype.constructor pointing to itself.

    Since functions can also behave like constructors, their .prototype.constructor property points to themselves as well. AFAIK, that’s unused in the language itself.

    The terse, technical answer? http://es5.github.com/#x11.8.6

    //foo instanceof bar
    Return the result of calling the [[HasInstance]] internal method of bar with argument foo.
    

    (slightly paraphrased)

    Basically, you’re asking mother-duck: “Excuse me ma’am, is this your child?” The child has little say in the matter.

    Edit: As mentioned in the comments, changing the prototype does indeed affect the instanceof results. Like above, there’s the intuitive answer and the technical answer.

    Intuitive answer is simple: The prototype defines the object. Therefore, changing the prototype changes the DNA – you make the duck a goose, not by teaching it to be a goose, but by going to its DNA and changing it to a goose DNA.

    The technicality is seeing what [[HasInstance]] does. (the other [[HasIntsance]] calls this one) The spec is really dry and terse, so here’s the algorithm written in pseudo-javascript:

    //assume Func is the function we're talking about
    function HasInstance ( value ) {
        if ( IsntAnObject(value) ) {
            return false;
        }
    
        var proto = Func.prototype;
    
        if ( Type(proto) !== "Object" ) {
            return false;
        }
    
        while ( value !== null ) {
            value = value.prototype;
            if ( value === proto ) {
                return true;
            }
        }
        return false;
    }
    

    As can be seen, by changing the prototype, we’re changing the behavior – value will be different values.

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

Sidebar

Related Questions

Recently I saw this piece of JavaScript code, but have been unable to understand
This might be a dumb question but I'm unable to understand: When we create
I am trying this code on GNU's C++ compiler and am unable to understand
I am unable to understand this error.This error is not in the class that
After reading this - What does 'synchronized' mean? I was still unable to understand
Here is my code.. but I am unable to understand this code. $('.maxlength') .after(<span></span>)
I'm currently studying indexers chapter, but I'm unable to understand this[int pos] and this[string
Please explain invokeAndWait() method in SwingUtilities.I am unable to understand this. Explain it very
I am unable to understand why I can't get a correct ISO-8859-1 charstet from
I am unable to understand how this works public void addToRule(Rule r) { if

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.