Configurable Write-Only Accessor

Define a configurable write-only accessor.

Usage

var setConfigurableWriteOnlyAccessor = require( '@stdlib/utils/define-configurable-write-only-accessor' );

setConfigurableWriteOnlyAccessor( obj, prop, setter )

Defines a configurable write-only accessor.

var obj = {};
var val = '';

function setter( v ) {
    val = v;
}

setConfigurableWriteOnlyAccessor( obj, 'foo', setter );

obj.foo = 'boop';

var bool = ( val === 'boop' );
// returns true
## Notes
  • Configurable write-only accessors are enumerable.

Examples

var setConfigurableWriteOnlyAccessor = require( '@stdlib/utils/define-configurable-write-only-accessor' );

function Foo( secret ) {
    if ( !(this instanceof Foo) ) {
        return new Foo( secret );
    }
    setConfigurableWriteOnlyAccessor( this, 'secret', setter );
    return this;

    function setter( v ) {
        secret = v;
    }
}

var foo = new Foo( 'beep' );

foo.secret = 'boop';