0

I need to change the field _value of x, but through the variable kot. How can I do that ?

   let x = {
    _value: "stas",

    set value(val) {
      this._value = val;
    },

    get value() {
      return this._value;
    }
  };

  let kot = {
    __proto__: x,
    name: 'kotiki'
  };

  console.log(kot);
Стас Рябцев
  • 1,318
  • 4
  • 19
  • 36
  • `kot.__proto__._value = "foo";` – Andreas Nov 30 '19 at 16:18
  • Why do you not want to create a `kot._value` property? Consider what should happen with a second object inheriting from `x`. It would be really weird if `x._value` changed. – Bergi Nov 30 '19 at 17:21
  • Just have your setter (and getter) [refer to `x._value` instead of `this._value`](https://stackoverflow.com/questions/10711064/javascript-object-literal-reference-in-own-keys-function-instead-of-this), then `kot.value = …` will do. – Bergi Nov 30 '19 at 17:22

0 Answers0