time-to-botec

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

README.md (2890B)


      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 # inheritedProperties
     22 
     23 > Return an array of an object's inherited property names and [symbols][@stdlib/symbol/ctor].
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var inheritedProperties = require( '@stdlib/utils/inherited-properties' );
     31 ```
     32 
     33 #### inheritedProperties( obj\[, level] )
     34 
     35 Returns an `array` of an object's inherited property names and [symbols][@stdlib/symbol/ctor].
     36 
     37 ```javascript
     38 var props = inheritedProperties( [ 1, 2, 3 ] );
     39 // returns [...]
     40 ```
     41 
     42 By default, the function walks an object's entire prototype chain. To limit the inheritance level, provide a `level` argument.
     43 
     44 ```javascript
     45 var props = inheritedProperties( [ 1, 2, 3 ], 1 );
     46 ```
     47 
     48 </section>
     49 
     50 <!-- /.usage -->
     51 
     52 <section class="notes">
     53 
     54 </section>
     55 
     56 <!-- /.notes -->
     57 
     58 <section class="examples">
     59 
     60 ## Examples
     61 
     62 <!-- eslint no-undef: "error" -->
     63 
     64 ```javascript
     65 var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
     66 var Symbol = require( '@stdlib/symbol/ctor' );
     67 var defineProperty = require( '@stdlib/utils/define-property' );
     68 var inheritedProperties = require( '@stdlib/utils/inherited-properties' );
     69 
     70 var hasSymbols;
     71 var props;
     72 var obj;
     73 
     74 hasSymbols = hasSymbolSupport();
     75 
     76 function Foo() {
     77     this.a = 'b';
     78     defineProperty( this, 'foo', {
     79         'configurable': false,
     80         'enumerable': false,
     81         'writable': false,
     82         'value': 'bar'
     83     });
     84     if ( hasSymbols ) {
     85         this[ Symbol( 'a' ) ] = 'b';
     86         defineProperty( this, 'beep', {
     87             'configurable': false,
     88             'enumerable': false,
     89             'writable': false,
     90             'value': 'boop'
     91         });
     92     }
     93     return this;
     94 }
     95 
     96 Foo.prototype.c = 'd';
     97 defineProperty( Foo.prototype, 'bip', {
     98     'configurable': false,
     99     'enumerable': false,
    100     'writable': false,
    101     'value': 'bap'
    102 });
    103 if ( hasSymbols ) {
    104     Foo.prototype[ Symbol( 'c' ) ] = 'd';
    105     defineProperty( Foo.prototype, Symbol( 'e' ), {
    106         'configurable': false,
    107         'enumerable': false,
    108         'writable': false,
    109         'value': 'f'
    110     });
    111 }
    112 
    113 obj = new Foo();
    114 props = inheritedProperties( obj );
    115 
    116 console.log( props );
    117 // => [ ..., 'c', 'bip', ... ]
    118 ```
    119 
    120 </section>
    121 
    122 <!-- /.examples -->
    123 
    124 <section class="links">
    125 
    126 [@stdlib/symbol/ctor]: https://www.npmjs.com/package/@stdlib/symbol-ctor
    127 
    128 </section>
    129 
    130 <!-- /.links -->