# Read-Only Accessor
> [Define][@stdlib/utils/define-property] a **read-only** accessor.
## Usage
```javascript
var setReadOnlyAccessor = require( '@stdlib/utils/define-read-only-accessor' );
```
#### setReadOnlyAccessor( obj, prop, getter )
[Defines][@stdlib/utils/define-property] a **read-only** accessor.
```javascript
function getter() {
return 'bar';
}
var obj = {};
setReadOnlyAccessor( obj, 'foo', getter );
obj.foo = 'boop';
// throws
```
## Notes
- Read-only accessors are **enumerable** and **non-configurable**.
## Examples
```javascript
var setReadOnlyAccessor = require( '@stdlib/utils/define-read-only-accessor' );
function Foo( name ) {
if ( !(this instanceof Foo) ) {
return new Foo( name );
}
setReadOnlyAccessor( this, 'name', getName );
return this;
function getName() {
return name;
}
}
var foo = new Foo( 'beep' );
try {
foo.name = 'boop';
} catch ( err ) {
console.error( err.message );
}
```
[@stdlib/utils/define-property]: https://www.npmjs.com/package/@stdlib/utils/tree/main/define-property