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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:50:45+00:00 2026-06-17T13:50:45+00:00

I was looking at the example on the MDN pages about Inheritance Revisited and

  • 0

I was looking at the example on the MDN pages about Inheritance Revisited and thought it would be nice to have the doSomething methods actually do something. So I started out with the following code, based on the example:

function A(a) { this.varA = a };
A.prototype = { varA: null, doSomething: function() { console.log('do something with ' + this.varA) } };
function B(a, b) {
    A.call(this, a);
    this.varB = b;
};
B.prototype = Object.create(new A(), {
    varB: { value: null, enumerable: true, configurable: true, writeable: true },
    doSomething: { value: function() {
        A.prototype.doSomething.apply(this, arguments);
        console.log("do something with " + this.varB);
    }, enumerable: true, configurable: true, writeable: true}
});
var b = new B('a', 'b');
b.doSomething();

I copy and pasted the code into the Chrome console and expected to be seeing

do something with a
do something with b

but instead I got

do something with a
do something with null

What am I overlooking here? Shouldn’t the call to “new B” result in the constructor which was defined above (function B(…)) being called? And if the constructor is called, shouldn’t b.varB have a value? How do I need to change the example so the output is as expected?

  • 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-17T13:50:46+00:00Added an answer on June 17, 2026 at 1:50 pm

    Accidentally you specified varB as being non-writable and hence the assignment this.varB = b failed (or was ignored).

    writeable: true should be spelled writable: true (without e). By default, properties defined using the a property descriptor are non-writable.

    So the whole descriptor becomes:

    varB: { value: null, enumerable: true, configurable: true, writable: true }
    

    Since you are assigning a value inside the constructor function anyway, you don’t really have to use the descriptor though.


    More information: MDN – Object.defineProperty.

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

Sidebar

Related Questions

I'm looking for example of how I would solve the scenario below: Imagine my
Problem: I'm looking example about creating model ( based on QAbstractItemModel ) to QTreeView
I have a view in which I search for products. I'm for example looking
Im looking for an example of multidimensional arrays. I have an array of thumbtails
I am looking for example where things in python would be easier to program
I would looking at example given alexhomes's hadoop-book here I could not understand why
I was looking at Example 2 on this msdn page about Thread synchronization with
I'm looking for example code for setting up a connection to a bluetooth device
I'm trying to learn Rails better by looking at example applications, and while looking
Looking for an example or documentation links as to how to implement a method

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.