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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:09:46+00:00 2026-06-07T21:09:46+00:00

Constructor1=function(){}; Constructor1.prototype.function1=function this_function() { // Suppose this function was called by the lines after

  • 0
Constructor1=function(){};
Constructor1.prototype.function1=function this_function()
{
  // Suppose this function was called by the lines after this code block
  // this_function - this function
  // this - the object that this function was called from, i.e. object1
  // ??? - the prototype that this function is in, i.e. Constructor1.prototype
}
Constructor2=function(){};
Constructor2.prototype=Object.create(Constructor1.prototype);
Constructor2.prototype.constructor=Constructor2;
object1=new Constructor2();
object1.function1();

How do I retrieve the last reference (indicated by ???) without knowing the name of the constructor?

For instance, say I had an object which inherits from a chain of prototypes. Can I know which prototype is used when I call a method on it?

Both seem theoretically possible, but I can’t find any way that works without more than constant number of assignment statements (if I have many such functions).

  • 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-07T21:09:47+00:00Added an answer on June 7, 2026 at 9:09 pm

    The prototype of each function has a reference back to the function via the constructor property [MDN]. So you can get the constructor function via

    var Constr = this.constructor;
    

    Getting the prototype is a bit trickier. In browsers supporting ECMAScript 5, you can use Object.getPrototypeOf [MDN]:

    var proto = Object.getPrototypeOf(this);
    

    In older browser it might be possible to get it via the non-standard __proto__ [MDN] property:

    var proto = this.__proto__;
    

    Can I know which prototype is used when I call a method on it?

    Yes, if the browser supports ES5. Then you have to repeatedly call Object.getPrototypeOf() until you find the object with that property. For example:

    function get_prototype_containing(object, property) {
        do {
            if(object.hasOwnProperty(property)) {
                break;
            }
            object = Object.getPrototypeOf(object);
        }
        while(object.constructor !== window.Object);
    
        // `object` is the prototype that contains `property`
        return object;
    }
    
    // somewhere else
    var proto = get_prototype_containing(this, 'function1');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This figure again shows that every object has a prototype. Constructor function Foo also
I have the below prog Object.prototype.inherit = function(baseConstructor) { this.prototype = (baseConstructor.prototype); this.prototype.constructor =
function Person() {} Person.prototype.population = 0; Person.prototype.constructor = function(name) { this.name = name; console.log(Name:
I have lots of code like this in my constructors:- function __construct($params) { $this->property
Say I have some code like this function Chart(start, end, controller, method, chart) {
I see a lot of code like this: function Base() {} function Sub() {}
// Don't break the function prototype. // pd - https://github.com/Raynos/pd var proto = Object.create(Function.prototype,
I want to create an inheritance function based on a prototype. I have this
I know that the prototype property of JavaScript function objects is copied to the
Suppose we have this constructor: var Foo = function(){ this.x = y; } Foo

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.