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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:49:51+00:00 2026-06-05T08:49:51+00:00

I am trying to get my head around Object Oriented Programming in Javascript and

  • 0

I am trying to get my head around Object Oriented Programming in Javascript and bumped into the following issue: (This is a simplified example of what can be found in Stoyan Stefanov’s book)

I create a constructor function to create Dog objects:

function Dog(){
this.tail = true;
}

Then I instantiate an object using Dog constructor function:

var benji = new Dog();

Then I assign a new property to Dog’s prototype object:

Dog.prototype.shout = 'Woof!';

Now, benji has access to both tail, as well as shout, as expected. All is well until I overwrite Dog’s prototype:

Dog.prototype = {paw : 4};

Now, benji.paw becomes undefined. My question is, shouldn’t benji have access to the new prototype object as well? What’s more baffling is, when I create a new instance of Dog after the prototype object was re-defined:

var lucy = new Dog();

lucy.paw evaluates to 4. lucy’s constructor object definition seems to be different from benji’s. I am quite confused what’s going on here, can someone explain how javascript’s memory model for objects work? Thanks.

  • 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-05T08:49:53+00:00Added an answer on June 5, 2026 at 8:49 am

    prototype is just an object.

    If you do

    var oldProto = Dog.prototype

    before you overwrite it

    Dog.prototype = { paws: 4 }

    then you can use the old prototype object for manipulations of its children:

    oldProto.teeth = true —> benji.teeth == true.

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

Sidebar

Related Questions

Trying to get my head around backbone.js. This example is using Backbone Boilerplate and
I'm trying to get my head around solving the following problem. I have the
I'm trying to get my head around JQuery Deferred object. I'm working on a
Really trying to get my head around this but cannot see the light through
I'm trying to get my head around the Discriminator on association example shipped with
I'm trying to get my head around this behaviour: I have a ListView on
I have been trying to get my head around this but it hasn't been
I'm trying to get my head around how object lifetime and reference counting interact
Just trying to get my head around Generics by reading this enlightening article by
I'm trying to get my head around NSNotificationCenter. If I have something like this

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.