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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:37:37+00:00 2026-06-13T18:37:37+00:00

Suppose I have a constructor: function Constructor(input) { this.input = input } Constructor.prototype.method =

  • 0

Suppose I have a constructor:

function Constructor(input) {
  this.input = input
}

Constructor.prototype.method = function() {
  console.log('a')
}

But I want to make another class using a copy of the constructor, but changing the prototypes.

function Constructor2(input) {
  this.input = input
}

Constructor2.prototype.method = function() {
  console.log('b')
}

I don’t want to redefine the constructor. How would you do this? Ideally it would be something as simple as:

var Constructor2 = inherits(Constructor)
Constructor2.prototype.method = // overwrite the inherited `method()`
  • 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-13T18:37:38+00:00Added an answer on June 13, 2026 at 6:37 pm
    var inherits = function(childCtor, parentCtor) {
      /** @constructor */
      function tempCtor() {};
      tempCtor.prototype = parentCtor.prototype;
      childCtor.superClass_ = parentCtor.prototype;
      childCtor.prototype = new tempCtor();
      /** @override */
      childCtor.prototype.constructor = childCtor;
    };
    
    
    
    // How to use it:
    
    var Constructor1 = function() {
    //add all your methods, variables etc
    };
    
    Constructor1.prototype.myMethod = function() {
    };
    
    var Contructor2 = function() {
    Contructor1.call(this); // Call the super class constructor
    };
    inherits(Contstructor2, Constructor1);
    // Constructor2 now inherits from Constructor1
    // override, add methods variables etc, whatever you need.
    
    // Have fun!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a class with a constructor (or other function) that takes a
Suppose we have this constructor: var Foo = function(){ this.x = y; } Foo
Suppose I have two constructor function: var Person = function(xx,xx,xxx,xxxxxxx) { //Person initialization }
Suppose I have a Generic abstract class that provides some default constructor functionality so
Suppose I have a static method of my class that returns an object of
Is there any way to make a function call only once? Suppose I have
Suppose I create a custom object/javascript class (airquotes) as follows: // Constructor function CustomObject(stringParam)
Suppose I have a function that tries to protect a global counter using this
I have the following function/constructor/method (I'm not sure exactly what it is) List<T>& List<T>::operator=(const
Suppose I have a struct list , and I want to provide a constructor

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.