define-read-only-property
v0.0.1-2
Published
⚡️ Sets a read-only property ⚡️
Downloads
3
Maintainers
Readme
Read-Only
Define a read-only property.
Usage
var setReadOnly = require("define-read-only-property");
setReadOnly( obj, prop, value )
Defines a read-only property.
var obj = {};
setReadOnly(obj, "foo", "bar");
obj.foo = "boop"; //=> throws
Examples
var setReadOnly = require("define-read-only-property");
class Foo {
constructor(name) {
setReadOnly(this, "name", name);
}
}
var foo = new Foo("beep");
try {
foo.name = "boop";
} catch (err) {
console.error(err.message);
}