Make the variable "_content" non-enumerable.
Blog.prototype = {
set content(newContent) {
Object.defineProperty(this, "_content", {
value: JSON.parse(newContent),
writable: true
});
},
get content() {
return this._content;
}
};
By default, the flag is "enumerable" for the property of the object falseif it is not explicitly specified in the call defineProperty().
- Symbol , , . IE :
Blog.prototype = () => {
const internalContent = Symbol("content key");
return {
set content(newContent) {
this[internalContent] = newContent;
},
get content() {
return this[internalContent];
}
};
}();
JSON.stringify(), defineProperty(). Symbol , . Symbol, Symbol(), .