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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:41:28+00:00 2026-06-07T12:41:28+00:00

I’m a beginner in Javascript, and having hard times trying to understand the relationship

  • 0

I’m a beginner in Javascript, and having hard times trying to understand the relationship between constructor and prototype properties.

I know that Prototype object has a constructor property that points to constructor function. And the constructor function has a prototype property that points back to the prototype object.

Here’s a code i’m trying to understand with (my questions are commented in the code) :

function Car(){};
var myCar = new Car();
console.log(Object.getPrototypeOf(myCar)); //why this prints "Car" Object ? isn't it the constructor not the prototype object ? why the prototype object is not printed ?


var Vehicle = {
    getName : function(){
        return "hello";
    }
};
Car.prototype = Vehicle ; //I'm trying to change the prototype property in the constructor to "Vehicle" Object is that done right ?
console.log(Object.getPrototypeOf(myCar).getName()); //Why am i getting getName() function does not exist ?
  • 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-07T12:41:30+00:00Added an answer on June 7, 2026 at 12:41 pm

    why this prints “Car” Object ? isn’t it the constructor not the prototype object ? why the prototype object is not printed ?

    That’s just how Chrome (or the browser you use) names the object. If you have a close look at the properties, it really is Car.prototype:

    enter image description here

    I’m trying to change the prototype property in the constructor to “Vehicle” Object is that done right ?

    You cannot change the prototype of an existing object, you can only extend it. Setting Car.prototype = Vehicle; will only change the prototype for future instances of Car, the existing ones will still refer to the original prototype object, which doesn’t have a getName property:

    // create a new instance after setting the new prototype
    var myCar2 = new Car();
    // yields false
    console.log(Object.getPrototypeOf(myCar) === Object.getPrototypeOf(myCar2)); 
    

    This really does not have anything to do with prototypes, but just how assignment and references work in JavaScript. Imagine I have the following object:

    var foo = {
        bar: {
            answer: 42
        }
    };
    

    and assume I assign foo.bar to a property of an other object:

    var baz = {};
    baz.xyz = foo.bar;
    

    Setting foo.bar to some other value now, like foo.bar = {}, won’t change the value of baz.xyz, it will still refer to the previous object.

    Only extending the original object (extending the prototype), or changing its properties will have an effect, since both, foo.bar and baz.xyz refer to the same object:

    foo.bar.answer = 21;
    console.log(baz.xyz.answer); // shows 21
    // console.log(foo.bar === baz.xyz); // yields true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.