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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:50:25+00:00 2026-06-05T13:50:25+00:00

I want to use inheritance concept in js, so what i did is function

  • 0

I want to use inheritance concept in js, so what i did is

function myGarage(x) {
        var _x = x;
        Object.defineProperty(this, "BenZ", {
            get: function () {
                return _x;
            },
            set: function (value) {
                _x = value;
            },
            enumerable: true,
            configurable: true
        });
    }
    myGarage.prototype = new MyCar();
    function MyCar() {
     var _x =0;
        Object.defineProperty(this, "Audi", {
            get: function () {
                return _x;
            },
            set: function (value) {
                _x = value;
            },
            enumerable: true,
            configurable: true
        });
    }

After this i created there instance for myGarage.

        var g1 = new myGarage(true);
        var g2 = new myGarage(false);
        var g3 = new myGarage("null");

The problem here is when i set g1.Audi = 10; all other instance of myGarage‘s Audi will hold the sample value

(eg)

    g1.Audi = 10;
    var a = g2.Audi // a is 10
    var b = g3.Audi; // b is 10

but i set the value to g1.

what i need is other instance must hold the default value or undefined

  • 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-05T13:50:27+00:00Added an answer on June 5, 2026 at 1:50 pm

    try the following code, this works fine,

    $(document).ready(function () {
    
            var g1 = new MyGarage(true);
            var g2 = new MyGarage(false);
            var g3 = new MyGarage("null");
            g1.Audi = 10;
            var a = g2.Audi
            var b = g3.Audi;
    
        });
        function MyCar() {
            var _x = 1;
            Object.defineProperty(this, "Audi", {
                get: function () {
                    return _x;
                },
                set: function (value) {
                    _x = value;
                },
                enumerable: true,
                configurable: true
            });
        }
        function MyGarage(x) {
            MyCar.apply(this, arguments);
            var _x = x;
            Object.defineProperty(this, "BenZ", {
                get: function () {
                    return _x;
                },
                set: function (value) {
                    _x = value;
                },
                enumerable: true,
                configurable: true
            });
        }
        MyGarage.prototype = new MyCar();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use inheritance to have an object treated in a different way
Could someone please explain when would I want to use delegation instead of inheritance?
I want use this 1 for using Bar code or QR code scanner. I
I want use javascript setInterval function to achieve a box rotate animate effect, I
With Yii php framework, I use inheritance. In my AbstractModel, I have this method:
I just read this nice article that taught me how to use inheritance (Table-per-hirarchy).
I'm thinking on new design for database. And I want to use Table-Per-Type inheritance
I want to use partials in rails along with single-table inheritance. I currently have
I have some object classes that use inheritance. It seems that I can only
I want to use mixed @Inheritance strategy, but Hibernate doesn't support it. Is there

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.