1.9 KiB
1.9 KiB
Configurable Read-Only
Define a configurable read-only property.
Usage
var setConfigurableReadOnly = require( '@stdlib/utils/define-configurable-read-only-property' );
setConfigurableReadOnly( obj, prop, value )
Defines a configurable read-only property.
var obj = {};
setConfigurableReadOnly( obj, 'foo', 'bar' );
obj.foo = 'boop';
// throws <Error>
Notes
- Configurable read-only properties are enumerable.
Examples
var setConfigurableReadOnly = require( '@stdlib/utils/define-configurable-read-only-property' );
function Foo( name ) {
if ( !(this instanceof Foo) ) {
return new Foo( name );
}
setConfigurableReadOnly( this, 'name', name );
return this;
}
var foo = new Foo( 'beep' );
try {
foo.name = 'boop';
} catch ( err ) {
console.error( err.message );
}