time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3005B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # enumerablePropertySymbols
     22 
     23 > Return an array of an object's own enumerable symbol properties.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 <!-- eslint-disable id-length -->
     30 
     31 ```javascript
     32 var enumerablePropertySymbols = require( '@stdlib/utils/enumerable-property-symbols' );
     33 ```
     34 
     35 #### enumerablePropertySymbols( obj )
     36 
     37 Returns an `array` of an object's own enumerable symbol properties.
     38 
     39 <!-- eslint-disable id-length -->
     40 
     41 ```javascript
     42 var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
     43 var Symbol = require( '@stdlib/symbol/ctor' );
     44 var defineProperty = require( '@stdlib/utils/define-property' );
     45 
     46 var obj = {};
     47 
     48 if ( hasSymbolSupport() ) {
     49     defineProperty( obj, Symbol( 'a' ), {
     50         'configurable': false,
     51         'enumerable': true,
     52         'writable': true,
     53         'value': 'b'
     54     });
     55 }
     56 
     57 var symbols = enumerablePropertySymbols( obj );
     58 ```
     59 
     60 </section>
     61 
     62 <!-- /.usage -->
     63 
     64 <section class="notes">
     65 
     66 ## Notes
     67 
     68 -   Property order is not guaranteed, as `object` property enumeration is not specified according to the [ECMAScript specification][ecma-262-for-in]. In practice, however, most engines use insertion order to sort an `object`'s properties, thus allowing for deterministic extraction.
     69 
     70 </section>
     71 
     72 <!-- /.notes -->
     73 
     74 <section class="examples">
     75 
     76 ## Examples
     77 
     78 <!-- eslint-disable id-length -->
     79 
     80 <!-- eslint no-undef: "error" -->
     81 
     82 ```javascript
     83 var defineProperty = require( '@stdlib/utils/define-property' );
     84 var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
     85 var Symbol = require( '@stdlib/symbol/ctor' );
     86 var enumerablePropertySymbols = require( '@stdlib/utils/enumerable-property-symbols' );
     87 
     88 var hasSymbols = hasSymbolSupport();
     89 var symbols;
     90 var obj;
     91 
     92 function Foo() {
     93     if ( hasSymbols ) {
     94         defineProperty( this, Symbol( 'baz' ), {
     95             'configurable': false,
     96             'enumerable': true,
     97             'writable': true,
     98             'value': 'qux'
     99         });
    100     }
    101     return this;
    102 }
    103 
    104 if ( hasSymbols ) {
    105     defineProperty( Foo.prototype, Symbol( 'bip' ), {
    106         'configurable': false,
    107         'enumerable': true,
    108         'writable': false,
    109         'value': 'bop'
    110     });
    111 }
    112 
    113 obj = new Foo();
    114 symbols = enumerablePropertySymbols( obj );
    115 
    116 console.log( symbols );
    117 ```
    118 
    119 </section>
    120 
    121 <!-- /.examples -->
    122 
    123 <section class="links">
    124 
    125 [ecma-262-for-in]: http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4
    126 
    127 </section>
    128 
    129 <!-- /.links -->