inheritedPropertySymbols

Return an array of an object's inherited symbol properties.

Usage

var inheritedPropertySymbols = require( '@stdlib/utils/inherited-property-symbols' );

inheritedPropertySymbols( obj[, level] )

Returns an array of an object's inherited symbol properties.

var symbols = inheritedPropertySymbols( [ 1, 2, 3 ] );

By default, the function walks an object's entire prototype chain. To limit the inheritance level, provide a level argument.

var symbols = inheritedPropertySymbols( [ 1, 2, 3 ], 1 );

Examples

var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
var Symbol = require( '@stdlib/symbol/ctor' );
var inheritedPropertySymbols = require( '@stdlib/utils/inherited-property-symbols' );

var hasSymbols;
var symbols;
var obj;

hasSymbols = hasSymbolSupport();

function Foo() {
    if ( hasSymbols ) {
        this[ Symbol( 'a' ) ] = 'b';
    }
    return this;
}

if ( hasSymbols ) {
    Foo.prototype[ Symbol( 'c' ) ] = 'd';
}

obj = new Foo();
symbols = inheritedPropertySymbols( obj );

console.log( symbols );
Did you find this page helpful?