@stdlib/symbol-ctor
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.6 • Public • Published

    Symbol

    NPM version Build Status Coverage Status dependencies

    Symbol factory.

    Installation

    npm install @stdlib/symbol-ctor

    Usage

    var Symbol = require( '@stdlib/symbol-ctor' );

    Symbol( [description] )

    Returns a Symbol primitive.

    var s = Symbol();
    // returns <symbol>

    To aid debugging, provide a symbol description.

    var s = Symbol( 'beep' );
    // returns <symbol>

    Notes

    • Unlike conventional constructors, the function does not support the new keyword.
    • The function is only supported in environments which support symbols. In non-supporting environments, the value is undefined.

    Examples

    var hasSymbolSupport = require( '@stdlib/assert-has-symbol-support' );
    var Symbol = require( '@stdlib/symbol-ctor' );
    
    var s;
    
    if ( hasSymbolSupport() ) {
        s = Symbol( 'beep' );
    
        // Print the value type:
        console.log( typeof s );
        // => 'symbol'
    
        // Serialize the symbol as a string:
        console.log( s.toString() );
        // => 'Symbol(beep)'
    
        // Test symbol equality:
        console.log( s === Symbol( 'beep' ) );
        // => false
    } else {
        console.log( 'Environment does not support symbols.' );
    }

    Notice

    This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

    For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

    Community

    Chat


    License

    See LICENSE.

    Copyright

    Copyright © 2016-2021. The Stdlib Authors.

    Install

    npm i @stdlib/symbol-ctor

    Homepage

    stdlib.io

    DownloadsWeekly Downloads

    98

    Version

    0.0.6

    License

    Apache-2.0

    Unpacked Size

    35 kB

    Total Files

    9

    Last publish

    Collaborators

    • stdlib-bot
    • kgryte
    • planeshifter
    • rreusser