I want to use the concept of inheritance in js, so what I did
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 that, I created an instance for myGarage .
var g1 = new myGarage(true); var g2 = new myGarage(false); var g3 = new myGarage("null");
The problem is here when I set g1.Audi = 10; all other instances of myGarage Audi will hold the sample value
(eg)
g1.Audi = 10; var a = g2.Audi
but I set the value to g1.
what i need is another instance should contain default or undefined
source share