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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:49:19+00:00 2026-05-26T22:49:19+00:00

I am struggling with a subject I previously thought I understood – prototypal inheritance

  • 0

I am struggling with a subject I previously thought I understood – prototypal inheritance in JavaScript.

I have a jsfiddle which outlines my problem here

I have a base object and an inheriting implementation. I want the implementation to make changes to the base’s properties, and for the base to access these updated properties.

Can anyone please point out where I’m going wrong?

  • 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-26T22:49:19+00:00Added an answer on May 26, 2026 at 10:49 pm

    The value of this when you call new cheeseBase() is the object you’re using as the prototype from inside “cheddar()”, and not the instance of “cheddar”. Thus, the “saySomething()” function always says “all cheese” because it refers to the “captured” this from the constructor call.

    If you change “saySomething()” to reference “this.favoriteCheese” in the “alert()” call, it says “cheddar” in the popup.

    If you really want the subclass to be modifying the base object, alternatively, you could rearrange:

    function cheesebase() {
    
        var that = this;
    
        this.favouriteCheese = "all cheese";
    
        this.setBaseCheese = function(chz) {
          that.favouriteCheese = chz;
        };
    
        this.saySomething = function() {
            alert("My favourite cheese is " + that.favouriteCheese);
        };
    }
    
    function cheddar() {
    
        var returnObject = Object.create(new cheesebase());
    
        returnObject.setBaseCheese("cheddar");
    
        returnObject.saySomethingElse = function() {
            alert("I like cheese");
        };
    
        return returnObject;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam struggling with NHibernate and its lazyload. I have a structure which I simplified
I have a problem that I have been struggling with for a few days
Struggling with the following problem. I have an attribute that defines the name of
Struggling here... I am trying to have views displayed during specific periods in a
im really struggling to find clear documentation on the following subject. I have created
Struggling with styling the mouse over for a button ... I have managed to
Been struggling with this simple selector problem a couple of hours now and must
im struggling with syntax here: hopefully this question is v simple, im just miising
been struggling with an issue now for a day or two. I have an
Attempting/struggling to get registration and sign-up working within an active admin project. I have

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.