JSFiddle - React, Tailwind, and code Playground
JavaScript
var box = {
locked: true,
unlock: function() { this.locked = false; },
lock: function() { this.locked = true; },
_content: ['hello', 'world'],
get content() {
if (this.locked) throw new Error("Заперто!");
return this._content;
}
};
box.unlock()
console.log(box.content)