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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:42:11+00:00 2026-06-15T01:42:11+00:00

I am learning the basics of OOP in Javascript and came across an inheritance

  • 0

I am learning the basics of OOP in Javascript and came across an inheritance example which is difference than what I’ve typically seen.

Typical:

ChildClass.prototype = new ParentClass();

Alternate Method:

function clone(object) {
  function OneShotConstructor(){}
  OneShotConstructor.prototype = object;
  return new OneShotConstructor();
}

SecondClass.prototype = clone(FirstClass.prototype);

Why would the latter be preferred when creating an object whose prototype is another object?

  • 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-15T01:42:13+00:00Added an answer on June 15, 2026 at 1:42 am

    Because you will invoke the constructor of the custom type (a.k.a. class) you are trying to inherit from. And that might have side effects. Imagine the following:

    var instancesOfParentClass = 0;
    function ParentClass (options) {
      instancesOfParentClass++;
      this.options = options;
    }
    
    function ChildClass () {}
    ChildClass.prototype = new ParentClass();
    

    Your counter has been incremented, but you didn’t really create a useful instance of ParentClass.

    Another problem, is that all instance properties (see this.options) will be present on ChildClass’ prototype, and you probably don’t want that.

    Note: When using constructor, you might have instance properties, and shared properties. For example:

    function Email (subject, body) {
      // instance properties
      this.subject = subject;
      this.body = body;
    }
    
    Email.prototype.send = function () {
      // do some AJAX to send email
    };
    
    // create instances of Email
    emailBob = new Email("Sup? Bob", "Bob, you are awesome!");
    emailJohn = new Email("Where's my money?", "John, you owe me one billion dollars!");
    
    // each of the objects (instances of Email) has its own subject 
    emailBob.subject // "Sup? Bob"
    emailJohn.subject // "Where's my money?"
    
    // but the method `send` is shared across instances
    emailBob.send === emailJohn.send // true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning the basics of Ruby (just starting out), and I came across the
I am learning basic concepts of OOP in C++ and I came across a
I am preparing a short tutorial for level 1 uni students learning JavaScript basics.
I recently started learning the basics of OOP in PHP. I am new to
I am learning the basics of javascript. now it DOM and i am stuck
As a beginner programmer, just now learning the basics of OOP, I've run into
I'm learning a basics of Smalltalk. There's a super keyword which is used to
I'm still learning basics of ruby so I thought I'd attempt to make a
I am learning basics of EJB 3.0. I have managed to get a sample
learning the basics of Python, now ready for a bigger challange... it didn't take

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.