| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Errors/Getter_only | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
TypeError: (Edge) TypeError: "x" (Firefox) TypeError: "prop" #<Object>, (Chrome)
, . . non-strict , TypeError strict mode.
, getter . , TypeError 30. . Object.defineProperty() .
"use strict";
function Archiver() {
var temperature = null;
Object.defineProperty(this, "temperature", {
get: function () {
console.log("get!");
return temperature;
},
});
}
var arc = new Archiver();
arc.temperature; // 'get!'
arc.temperature = 30;
// TypeError: setting getter-only property "temperature"
, 16, temperature, , , :
"use strict";
function Archiver() {
var temperature = null;
var archive = [];
Object.defineProperty(this, "temperature", {
get: function () {
console.log("get!");
return temperature;
},
set: function (value) {
temperature = value;
archive.push({ val: temperature });
},
});
this.getArchive = function () {
return archive;
};
}
var arc = new Archiver();
arc.temperature; // 'get!'
arc.temperature = 11;
arc.temperature = 13;
arc.getArchive(); // [{ val: 11 }, { val: 13 }]
This page was last modified on 7 . 2023 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |