time-to-botec

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

README.md (4130B)


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