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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:21:59+00:00 2026-05-11T01:21:59+00:00

I see a lot of code like this: function Base() {} function Sub() {}

  • 0

I see a lot of code like this:

function Base() {} function Sub() {} Sub.prototype = new Base(); 

However, if you do:

s = new Sub(); print(s.constructor == Sub); 

This is false. This seems confusing to me, since s’s constructor is, indeed, Sub. Is it conventional/better to do this?

function Base() {} function Sub() {} Sub.prototype = new Base(); Sub.prototype.constructor = Sub; 

or does it not really matter?

  • 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. 2026-05-11T01:22:00+00:00Added an answer on May 11, 2026 at 1:22 am

    ‘constructor’ doesn’t do what it looks like it does. This, in addition to its non-standardness, is a good reason to avoid using it – stick with instanceof and prototype.

    Technically: ‘constructor’ is not a property of the ‘s’ instance, it is a property of the ‘Sub’ prototype object showing through. When you create the ‘Sub’ function in Mozilla, you get a newly-minted default Sub.prototype object which has a ‘constructor’ pointing back to the Sub function as a courtesy.

    However you then replace that prototype with a new Base(). The original default prototype with the link back to Sub is lost; instead, Sub.prototype is an instance of Base without any overriding ‘constructor’ property. So:

    new Sub().constructor=== Sub.prototype.constructor=== new Base().constructor=== Base.prototype.constructor=== Base 

    …all the way down to the most basic object whose prototype you didn’t change.

    Is it conventional/better to do this?

    When dealing with JavaScript objects/classes there is no one convention; every library’s metaclass system behaves slightly differently. I haven’t seen one that writes ‘constructor’ to each derived class manually, but it seems as good a solution as any if you really want to have the real constructor available; it will also make the code compatible with browsers/engines that don’t give you ‘constructor’.

    I’d consider giving it a different name, though, to avoid confusion with the existing and differently-behaving ‘constructor’ property.

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

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Stylesheet div.figure img, div.figure div.caption { width: 100%; } div.figure… May 11, 2026 at 2:03 pm
  • added an answer According to the documentation, “The leftmost SQL parameter has an… May 11, 2026 at 2:03 pm
  • added an answer I found the problem, a seely problem as usual... I… May 11, 2026 at 2:03 pm

Related Questions

I see a lot of example code for C# classes that does this: public
I see a lot of talk on here about functional languages and stuff. Why
I see a lot of IoC frameworks for .Net and Java. Does anyone know
I am looking into captive portals for my organization. I see a lot of
I'm having some inheritance issues as I've got a group of inter-related abstract classes
A lot of times in code on the internet or code from my co-workers
Well I tried to figure out is this possible in any way. Here is
Well, I have this bit of code that is slowing down the program hugely

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.