time-to-botec

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

README.md (3758B)


      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 # inheritedEnumerablePropertySymbols
     22 
     23 > Return an array of an object's inherited enumerable [symbol][@stdlib/symbol/ctor] properties.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 <!-- eslint-disable id-length -->
     30 
     31 ```javascript
     32 var inheritedEnumerablePropertySymbols = require( '@stdlib/utils/inherited-enumerable-property-symbols' );
     33 ```
     34 
     35 #### inheritedEnumerablePropertySymbols( obj\[, level] )
     36 
     37 Returns an `array` of an object's inherited enumerable [symbol][@stdlib/symbol/ctor] properties.
     38 
     39 ```javascript
     40 var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
     41 var Symbol = require( '@stdlib/symbol/ctor' );
     42 
     43 var hasSymbols = hasSymbolSupport();
     44 var symbols;
     45 var f;
     46 
     47 function Foo() {
     48     if ( hasSymbols ) {
     49         this[ Symbol( 'a' ) ] = 'a';
     50     }
     51     return this;
     52 }
     53 
     54 if ( hasSymbols ) {
     55     Foo.prototype[ Symbol( 'b' ) ] = 'b';
     56 }
     57 
     58 f = new Foo();
     59 symbols = inheritedEnumerablePropertySymbols( f );
     60 ```
     61 
     62 By default, the function walks an object's entire prototype chain. To limit the inheritance level, provide a `level` argument.
     63 
     64 ```javascript
     65 var symbols = inheritedEnumerablePropertySymbols( [], 1 );
     66 ```
     67 
     68 </section>
     69 
     70 <!-- /.usage -->
     71 
     72 <section class="notes">
     73 
     74 ## Notes
     75 
     76 -   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.
     77 
     78 </section>
     79 
     80 <!-- /.notes -->
     81 
     82 <section class="examples">
     83 
     84 ## Examples
     85 
     86 <!-- eslint-disable id-length -->
     87 
     88 <!-- eslint no-undef: "error" -->
     89 
     90 ```javascript
     91 var defineProperty = require( '@stdlib/utils/define-property' );
     92 var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
     93 var Symbol = require( '@stdlib/symbol/ctor' );
     94 var inheritedEnumerablePropertySymbols = require( '@stdlib/utils/inherited-enumerable-property-symbols' );
     95 
     96 var hasSymbols = hasSymbolSupport();
     97 var symbols;
     98 var obj;
     99 
    100 function Foo() {
    101     this.a = 'a';
    102     defineProperty( this, 'b', {
    103         'configurable': false,
    104         'enumerable': false,
    105         'writable': true,
    106         'value': 'b'
    107     });
    108     if ( hasSymbols ) {
    109         this[ Symbol( 'a' ) ] = 'a';
    110         defineProperty( this, Symbol( 'b' ), {
    111             'configurable': false,
    112             'enumerable': false,
    113             'writable': false,
    114             'value': 'b'
    115         });
    116     }
    117     return this;
    118 }
    119 
    120 Foo.prototype.c = 'c';
    121 defineProperty( Foo.prototype, 'd', {
    122     'configurable': false,
    123     'enumerable': false,
    124     'writable': false,
    125     'value': 'd'
    126 });
    127 if ( hasSymbols ) {
    128     Foo.prototype[ Symbol( 'c' ) ] = 'c';
    129     defineProperty( Foo.prototype, Symbol( 'd' ), {
    130         'configurable': false,
    131         'enumerable': false,
    132         'writable': false,
    133         'value': 'd'
    134     });
    135 }
    136 
    137 obj = new Foo();
    138 symbols = inheritedEnumerablePropertySymbols( obj );
    139 
    140 console.log( symbols );
    141 ```
    142 
    143 </section>
    144 
    145 <!-- /.examples -->
    146 
    147 <section class="links">
    148 
    149 [ecma-262-for-in]: http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4
    150 
    151 [@stdlib/symbol/ctor]: https://www.npmjs.com/package/@stdlib/symbol-ctor
    152 
    153 </section>
    154 
    155 <!-- /.links -->