Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS Overwrite prevention
/* Overwrite prevention */
var obj = {
foo: 'this is the value of foo'
};
Object.defineProperties(obj, {
'getFoo': {
value: function () {
return this.foo;
}
},
'setFoo': {
value: function (val) {
this.foo = val;
}
}
});
obj.getFoo = 66;
// getFoo is not going to be overwritten!
console.log(obj.getFoo());
// "this is the value of foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.