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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:01:49+00:00 2026-06-04T16:01:49+00:00

Given this bit of code: var SuperClass = function(a, b) { this.a = a;

  • 0

Given this bit of code:

var SuperClass = function(a, b) {
  this.a = a;
  this.b = b;
};

SuperClass.prototype.getA = function() {
  return this.a;
};

var SubClass = function(a, b, c) {
  SuperClass.call(this, a, b);
  this.c = c;
};

In order to initiate the SubClass prototype, most recommendations seem to be the following:

SubClass.prototype = new SuperClass();

It seems odd to me to create (instantiate) a new SuperClass object (with its own a and b properties) just to serve as the prototype for the SubClass.

This also works:

// anti-pattern
SubClass.prototype = SuperClass.prototype;

but it passes the SuperClass.prototype object by reference, so anything you add to the SubClass.prototype is also added to the SuperClass.prototype, because they are the same object. This is not expected behavior in most cases.

QUESTION: Is there a way to achieve the proper prototyping without creating an instance of the SuperClass to serve as the SubClass‘s base prototype?

  • 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-04T16:01:51+00:00Added an answer on June 4, 2026 at 4:01 pm

    Under modern browsers:

    SubClass.prototype = Object.create( SuperClass.prototype );
    

    This lets you create an object with a defined __proto__ without invoking the ‘constructor’ method of the parent class. For more details, read up on Object.create (including a polyfill implementation for older browsers).

    Seen in action:

    function Foo(){ console.log("AHHH!"); }
    Foo.prototype.foo = 42;
    function Bar(){}
    Bar.prototype = Object.create(Foo.prototype);  // Note: no "AHHH!" shown
    Bar.prototype.bar = 17;
    
    // Showing that multi-level inheritance works
    var b = new Bar;
    console.log(b.foo,b.bar); //-> 42, 17
    
    // Showing that the child does not corrupt the parent
    var f = new Foo;          //-> "AHHH!"
    console.log(f.foo,f.bar); //-> 42, undefined
    
    // Showing that the inheritance is "live"
    Foo.prototype.jim = "jam";
    console.log(b.jim);       //-> "jam"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
Given the following code var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type':
I know this is a bit bleeding edge, but here's the question anyway: Given
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
I have the following code for getting the MSB (Most Significant Bit) from a
I'm running this scala code on a 32-bit quad-core Core2 system: def job(i:Int,s:Int):Long =
I need a bit of clarification on jQuery caching. To my understanding, this: var
This is a bit hard to explain but I'll give it a go. Lets
Sorry if this is a bit random, but is it good practice to give
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[

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.