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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:13:32+00:00 2026-05-27T02:13:32+00:00

Begin with an simple attempt, I defined an Constructor and used it to create

  • 0

Begin with an simple attempt, I defined an Constructor and used it to create an instance myobject:

function MyConstructor () {};
var myobject = new MyConstructor ();

Then, I modified the prototype property of this Constructor and created another instance myobject1 with it:

MyConstructor.prototype = {};
var myobject1 = new MyConstructor ();

I repeated the same procedure and created another instance myobject2:

MyConstructor.prototype = {name: '2'};
var myobject2 = new MyConstructor ();

Now I am testing the constructor property of each instance, which is not what I expect:

myobject.constructor == MyConstructor;
//true
myobject1.constructor == MyConstructor;
//false
myobject2.constructor == MyConstructor;
//false

When looking up the [[prototype]], it is different from each other.

myobject.__proto__ == myobject1.__proto__
//false
myobject2.__proto__ == myobject1.__proto__
//false

Could anyone explain what happens to MyConstructor when changing its prototype property?

  • 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-27T02:13:32+00:00Added an answer on May 27, 2026 at 2:13 am

    When you creating constructor:

    function MyConstructor() {};
    

    it has prototype.constructor set to MyConstructor:

    MyConstructor.prototype.constructor === MyConstructor; //true
    

    When you overwrite prototype of MyConstructor by

    MyConstructor.prototype = { foo: function () {} };
    

    then origignal MyConstructor.prototype object is replaced by passed object { foo: function () {} } and this object does not have property ‘constructor’ set to MyConstructor but to function Object because Object is constructor bound to all object created by object literals.

    So after this:

    MyConstructor.prototype = { foo: function () {} };
    MyConstructor.prototype.constructor === Object;
    

    and when you create new object with this constructor

    var foo = new MyConstructor();
    

    then:

    foo.constructor === Object; // true
    

    so to repair this problem, after you overwrite prototype then you have to correct constructor field:

    MyConstructor.prototype = { foo: function () {} };
    MyConstructor.prototype.constructor = MyConstructor;
    

    and then your constructor has prototype with correct constructor field.
    You could also write:

    MyConstructor.prototype = { foo: function () {}, constructor: MyConstructor };
    

    and final effect will be the same.

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

Sidebar

Related Questions

I have created simple function create function TRIM(@data varchar(20)) returns varchar(100) as begin declare
I'm trying to execute my simple SQL code to create a table. BEGIN TRANSACTION;
I have written a simple procedure: CREATE PROCEDURE [dbo].[sp_GetPublishedDocs2] @FromDate as Datetime AS BEGIN
Simple question; what's better and why? out.resize( in.size() ); T1::iterator outit = out.begin(); for(
I will begin this question by admitting I am very new to MVC. The
I am trying to create a simple event scheduler for my campus, as an
var slideshow_photos = [ http://domain/2294484.jpg , http://domain/2294485.jpg , http://domain/2294488.jpg ]; </script> <!-- begin I
simple question here, I am writing a function, but I was having trouble setting
I have a simple function written in Oracle 9i (version 9.2.0.4.0) to simulate an
I've got this simple SPROC: BEGIN -- SET NOCOUNT ON added to prevent extra

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.