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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:49:18+00:00 2026-06-05T07:49:18+00:00

i have made two classes, which is person – the parent class and a

  • 0

i have made two classes, which is person – the parent class and a student class – the child class. i am trying to implement inheritance. also i am trying to implement it in modular pattern. but its not getting properly. for the code block please check below.

Person.js

var Person = function() {

    var details, constructor, getDetailsByAttribute, setDetailsByAttribute, setDetails, getDetails, clearDetails;

    clearDetails = function()   {
        details = {
            uid : '',
            name : '',
            email : ''
        };
    };

    getDetailsByAttribute = function(attr)  {
        return details[attr];
    };

    setDetailsByAttribute = function(key, value)    {
        if(details.hasOwnProperty(key)) {
            details[key] = value;
        }else   {
            console.log('invalid key');
        }
    };

    setDetails = function(param)    {
        clearDetails();
        for(var attr in param)  {
            if(details.hasOwnProperty(attr))    {
                details[attr] = param[attr];
            }
        }
    };

    getDetails = function() {
        return details;
    };

    /**
     * During object creation;
     */
    if(arguments.length >= 1)   {
        //clearDetails();
        setDetails(arguments[0]);
    }

    return {
        getDetailsByAttribute : function(attr)  {
            return getDetailsByAttribute(attr);
        },

        setDetailsByAttribute : function(key, value)    {
            setDetailsByAttribute(key, value);
        },

        setDetails : function(params)   {
            setDetails(params);
        },

        getDetails : function() {
            return getDetails();
        },

        clearDetails : function()   {
            clearDetails();
        }
    };
};

Student.js

var Student = function()    {
    Person.call(this,arguments);
};

Student.prototype = new Person();

index.html

<html>
    <head>
    </head>
    <body>
        <script type="text/javascript" src="modules/Person.js"></script>
        <script type="text/javascript" src="modules/Student.js"></script>
        <script type="text/javascript">
            var person1, person2, person3, student1;

            person1 = new Person({
                uid : 5225,
                name : 'jaison',
                email : 'jaison@jaison.com'
            });

            person2 = new Person({
                uid : 5222,
                name : 'jatin',
                email : 'jatin@jatin.com'
            });

            person3 = new Person();
            person3.setDetails({
                uid : 5221,
                name : 'sarath',
                email : 'sarath@sarath.com'
            });
            person3.setDetailsByAttribute('name', 'sarath');

            student1 = new Student({
                uid : 5221,
                name : 'sachin',
                email : 'sachin@sachin.com'
            });

            console.log('person 1 : ',person1.getDetails());
            console.log('person 2 : ',person2.getDetails());
            console.log('person 3 : ',person3.getDetails());
            console.log('student 1 : ',student1.getDetails());
            //console.log(student1.get);

        </script>
    </body>
</html>
  • 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-05T07:49:20+00:00Added an answer on June 5, 2026 at 7:49 am

    try this:

    var Student = function()    {
        return Person.apply(this, arguments);
    };
    

    without

    Student.prototype = new Person();
    

    UPDATE: I just realize that you can use this:

    var Student = function()    {
        this.setDetails.apply(this, arguments);
    };
    Student.prototype = new Person();
    

    So the closure will be inside prototype, and setDetails will access it.

    In your code when you do this:

    Student.prototype = new Person();
    

    you create a closure and when You call this

    var Student = function()    {
        Person.call(this,arguments);
    };
    

    you create another closure (and it should not be call but apply, but even that it will not work). you execute constructor as a function and (if it will be apply it will) apply arguments to different closure, and all those functions that are returned by Person with detail inside the closure will be discard. methods of Student will be taken from prototype not from constructor.

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

Sidebar

Related Questions

I have a very simple composite model made of two classes: Public Class ParentModelVM
I have two Classes which are made up of two DateTime values. A start
I have made a list view containing two childs. Now i am trying to
I have a base class Element and derived two other classes from it, Solid
in eclipse plugin i have two plug-in which are used there own class loader
I have two classes, CheckboxItemsList which extends a generic list, and CheckboxItems , which
I have created a debugger visualizer in VS2008. There are two classes i've made,
Today, I've stumbled over the following: Consider two classes NewClass and NewClass1, which have
I have seen there are two partial classes of same class(FORM) in C# winforms.
Alright so I'm trying to create a method called: setIncrement(). I have two classes

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.