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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:49:32+00:00 2026-06-10T19:49:32+00:00

Since when we declare a function we get its prototype’s constructor property point to

  • 0

Since when we declare a function we get its prototype’s constructor property point to the function itself, is it a bad practice to overwrite function’s prototype like so:

function LolCat() {
}

// at this point LolCat.prototype.constructor === LolCat

LolCat.prototype = {
    hello: function () {
        alert('meow!');
    }
    // other method declarations go here as well
};

// But now LolCat.prototype.constructor no longer points to LolCat function itself

var cat = new LolCat();

cat.hello(); // alerts 'meow!', as expected

cat instanceof LolCat // returns true, as expected

This is not how I do it, I still prefer the following approach

LolCat.prototype.hello = function () { ... }

but I often see other people doing this.

So are there any implications or drawbacks by removing the constructor reference from the prototype by overwriting the function’s prototype object for the sake of convenience as in the first example?

  • 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-10T19:49:34+00:00Added an answer on June 10, 2026 at 7:49 pm

    I can’t see anyone mentioning best practice as far as this is concerned, so I think it comes down to whether you can see the constructor property ever being useful.

    One thing worth noting is that the constructor property, if you don’t destroy it, will be available on the created object too. It seems to me like that could be useful:

    var ClassOne = function() {alert("created one");}
    var ClassTwo = function() {alert("created two");}
    
    ClassOne.prototype.aProperty = "hello world"; // preserve constructor
    ClassTwo.prototype = {aProperty: "hello world"}; // destroy constructor
    
    var objectOne = new ClassOne(); // alerts "created one"
    var objectTwo = new ClassTwo(); // alerts "created two"
    
    objectOne.constructor(); // alerts "created one" again
    objectTwo.constructor(); // creates and returns an empty object instance
    

    So it seems to me that it’s an architectural decision. Do you want to allow a created object to re-call its constructor after it’s instantiated? If so preserve it. If not, destroy it.

    Note that the constructor of objectTwo is now exactly equal to the standard Object constructor function – useless.

    objectTwo.constructor === Object; // true
    

    So calling new objectTwo.constructor() is equivalent to new Object().

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

Sidebar

Related Questions

According to my teacher, it's bad practice to write user-defined functions like this: int
Since each thread has its own stack, its private data can be put on
There is a JDK function that, although the javadocs does not declare it as
So consider a function like this: public void setTemperature(double newTemperatureValue, TemperatureUnit unit) where TemperatureUnit
since memcpy should be highly optimized nowadays, does it still make sense to optimize
Since regular jQuery animations are not fluent on iOS ( .hide() , slideDown() ),
since today im facing a strange problem. When i start my app in my
Since I am developing an iOS >= 5.0 application, I am trying to change
Since REST is stateless, each request that comes in has no knowledge of the
Since now I have only used plugin for editing and the way I use

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.