time-to-botec

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

README.md (4048B)


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