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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:08:28+00:00 2026-06-01T14:08:28+00:00

I have read through some tutorials about javascript prototypal inheritance patterns but I am

  • 0

I have read through some tutorials about javascript prototypal inheritance patterns but I am not sure which is the best practice out of the following two. I noted that many people do this inheritance pattern:

var A = function (){}
A.prototype = {} 

var B = function () {
    A.apply(this, arguments); // Calling the constructor of A
}
B.prototype = new A(); // Inherit from A through an instance

Alternative, there are some sources that do the following pattern instead:

var A = function (){}
A.prototype = {} 

var B = function () {
    A.apply(this, arguments); // Calling the constructor of A
}
for (var prop in A.prototype) {
    B.prototype[prop] = A.prototype[prop]; // Inherit from A by copying every property/methods from A
}

Although both patterns work, I rarely see people use the latter inheritance pattern (ie. copying each property/methods from the parent’s prototype) – why? Is there something wrong with copying properties/methods directly from parent to child? Also, are these two patterns intrinsically different in some ways?

Thank you.

  • 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-01T14:08:30+00:00Added an answer on June 1, 2026 at 2:08 pm

    These patterns are very different, and as you may have guessed, the first is better (but not the best possible). Let us compare:

    The Most Modern, Best Pattern

    B.prototype = Object.create(A.prototype);
    

    This uses the Object.create function to set B.prototype to a new object, whose internal [[Prototype]] is A.prototype. This is basically exactly what you want: it will make B instances delegate to A.prototype when appropriate.

    The Original Pattern

    B.prototype = new A();
    

    This was how things used to be done, before ES5’s Object.create came about. (Although there were workarounds, even if they were not widely used.) The problem with this approach is that any instance-only data properties also end up on B.prototype, which is not desired. Additionally, any side effects of calling A‘s constructor will happen. Essentially this approach muddles two related, but different concepts: object instantiation, and object construction.

    The Non-Standard Pattern from Your Post

    for (var prop in A.prototype) {
        B.prototype[prop] = A.prototype[prop];
    }
    

    This pattern has several problems:

    • It will copy properties from everywhere in A‘s prototype chain, all the way down to Object, directly into B.prototype. This defeats much of the purpose of prototypal inheritance, wherein you should be delegating up the prototype chain, instead of squashing it into one single level.
    • It only gets enumerable properties from A.prototype and its prototype chain, since for ... in skips non-enumerable properties.
    • It messes up any getters or setters defined on A.prototype (or its prototype chain), simply copying over their value instead of the getter/setter functions.
    • It will look effin’ weird to anyone trying to read your code.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just starting out with QT. I have read through some tutorials, and
I just started with ASP.NET MVC 1.0. I've read through some tutorials but I
I have read through several reviews on Amazon and some books seem outdated. I
I need to read and write some data through named pipes. I have tested
I have read through the solutions to similar problems, but they all seem to
I've read through a number of topics now and have not found one quite
i HAVE read many Tutorials on posting to twitter using OAuth like here but
I have read through the Rails docs for Routing , Restful Resources , and
Okay guys, I have read through all the other posts and question on jQuery
Ok, I'm programming in objective-C and using Xcode. I have read through the documentation

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.