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 8167875

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:20:25+00:00 2026-06-06T20:20:25+00:00

Suppose I have two constructor function: var Person = function(xx,xx,xxx,xxxxxxx) { //Person initialization }

  • 0

Suppose I have two constructor function:

var Person = function(xx,xx,xxx,xxxxxxx) {
  //Person initialization
}

var Man = function(xx,xx,xxx,xxx) {
  //Man initialization
}

And I want Man extends from Person.

The following is what I thought:

Given a created Man object:

var m=new Man("xx",....);

1) when a property of m is accessed,it will search it in Man.prototype.

2) If not find, It should find it in Man.prototype.__prop__.

So what I have do is make the Man.prototype.__prop__ linked to Person.prototype.

I know this is the common way:

function inherit(superClass) {
    function F() {}
    F.prototype = superClass.prototype;
    return new F;
}
Man.prototype=inherit(Person);

But when I try this:

Man.prototype.prototype=Person.prototype.

Why it does not work?

  • 0 0 Answers
  • 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-06T20:20:27+00:00Added an answer on June 6, 2026 at 8:20 pm

    It sounds like you actually want to link instances of Man to an instance of Person that retains any properties added in its constructor, in which case you might really want something like this:

    function Person(a, b) {
        this.a = a;
        this.b = b;
    }
    
    function Man() {}
    Man.prototype = new Person("val1", "val2");
    
    var m = new Man();
    console.log(m.a);
    

    …which prints val1.

    Additional Ramblings

    The purpose of inherit is to create an object from a function whose prototype is that of the given super class (without explicitly using new), which is exactly what it does. Therefore, the following prints string:

    function Person() {}
    Person.prototype.test = "string";
    
    function Man() {}
    
    function inherit(superClass) {
        function F() {}
        F.prototype = superClass.prototype;
        return new F;
    }
    
    var t = inherit(Person);
    console.log(t.test);
    

    But you generally want to assign the returned object to another function’s prototype:

    Man.prototype = inherit(Person);
    
    var m = new Man();
    console.log(m.test);
    

    …so that m.test also prints string, which means that objects created using Man are linked to Person‘s prototype).

    Note that Man.prototype.prototype is undefined and — this is the important part — also meaningless. Functions have prototypes. Other objects (such as Man.prototype) do not. The prototype property is not magical in any other context. Assigning a value to a random object’s prototype property doesn’t do anything special. It’s just another property.

    Note also that the thing we returned from inherit is linked to Person by way of its prototype and has no access to any properties added to instances of Person.

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

Sidebar

Related Questions

Suppose I have two h:inputText components. I want to bind both of the text
Suppose I have two tables Main and Other like the following: Main +----------+-----------------------------------+ |
Suppose we have following two classes: class Temp{ public: char a; char b; };
I have two constructor : function clsUsagerEmailUserName($nickName, $email) { $this->nickName = $nickName; $this->email =
Suppose I have two types, TypeA and TypeB, that I want to register with
My questions is, suppose we have two classes A and B. I want to
Suppose I have the following two classes in two different assemblies: //in assembly A
Suppose I have two tables, - emp(empId number(1),empName varchar2(50)) and - manager(manId number(5),managerName varchar2(100))
Suppose we have two classes: class Base { private: int x; public: void f();
Suppose we have two tables Foo and Bar. I have an association table Foo_Bar

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.