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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:00:21+00:00 2026-06-06T05:00:21+00:00

When we use prototype . we use like function classA(){ } function classB(){ }

  • 0

When we use prototype . we use like

function classA(){

}
function classB(){

}

classB.prototype = new classA();

why should we write it like that? why isn’t it?

classB.prototype = classA;

after I set the prototype is classA; then I log the classB.prototype. the console log like following

function classA(){
}

what’s that mean? I try to add some method into classA but I can NOT call them by using classB.prototype.BLABLA.

my english is not so good. so . I don’t know if I explain it well or not.

  • 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-06T05:00:23+00:00Added an answer on June 6, 2026 at 5:00 am

    why isn’t it? classB.prototype = classA;

    Because all instances of classB would inherit from the function classA which is usually not what you want. Instances of classB would inherit all properties of function objects, such as .call [MDN] and .apply [MDN]. They would not inherit properties you assigning to an instance inside the constructor function or to the prototype of classA.

    why should we write it like that?

    You want each instance of classB having the same properties as an instance of classA.


    But even classB.prototype = new classA(); is not a very good approach. What if classA expects arguments passed to the constructor?

    Better let instances of classB inherit from classA‘s prototype, like:

    classB.prototype = Object.create(classA.prototype);
    classB.prototype.constructor = classB;
    

    And in the constructor, you are calling the parent constructor on the new instance:

    function classB(){
        classA.apply(this, arguments);
    }
    

    Reference: Object.create

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

Sidebar

Related Questions

Whenever I use the splice method in Javascript like so: Array.prototype.mymethod = function() {
When I try to use this in my Javascript prototype like so: Array.prototype.sample =
QTableWidget::setItemPrototype says following. The table widget will use the item prototype clone function when
Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param)
let's say I have a JavaScript-Class like this: Foo.prototype = { init: function() {
I'm trying to build a jQuery.live like function. Helper is a class that has
I would like to create a Javascript class that I can use like so:
I want to write a function that creates a Vector (template), stores a couple
I use prototype since a long time, but for some reason I have to
I am trying to use Prototype and startsWith but I want to check a

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.