Non-Enumerable Write-Only Accessor

Define a non-enumerable write-only accessor.

Usage

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

setNonEnumerableWriteOnlyAccessor( obj, prop, setter )

Defines a non-enumerable write-only accessor.

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

function setter( v ) {
    val = v;
}

setNonEnumerableWriteOnlyAccessor( obj, 'foo', setter );

obj.foo = 'boop';

var bool = ( val === 'boop' );
// returns true

Notes

  • Non-enumerable write-only accessors are non-configurable.

Examples

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

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

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

var foo = new Foo( 'beep' );

foo.secret = 'boop';
Did you find this page helpful?