time-to-botec

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

README.md (2909B)


      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 # inheritedPropertyDescriptors
     22 
     23 > Return an object's inherited [property descriptors][@stdlib/utils/property-descriptors].
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 <!-- eslint-disable id-length -->
     30 
     31 ```javascript
     32 var inheritedPropertyDescriptors = require( '@stdlib/utils/inherited-property-descriptors' );
     33 ```
     34 
     35 #### inheritedPropertyDescriptors( obj\[, level] )
     36 
     37 Returns an object's inherited [property descriptors][@stdlib/utils/property-descriptors].
     38 
     39 ```javascript
     40 function Foo() {
     41     this.a = 'b';
     42     return this;
     43 }
     44 
     45 Foo.prototype.beep = 'boop';
     46 
     47 var f = new Foo();
     48 var desc = inheritedPropertyDescriptors( f );
     49 // returns { 'beep': {...}, ... }
     50 ```
     51 
     52 By default, the function walks an object's entire prototype chain. To limit the inheritance level, provide a `level` argument.
     53 
     54 ```javascript
     55 var inherit = require( '@stdlib/utils/inherit' );
     56 
     57 function Bar() {
     58     return this;
     59 }
     60 
     61 Bar.prototype.boop = 'beep';
     62 
     63 function Foo() {
     64     Bar.call( this );
     65     this.a = 'b';
     66     return this;
     67 }
     68 
     69 inherit( Foo, Bar );
     70 Foo.prototype.beep = 'boop';
     71 
     72 var f = new Foo();
     73 var desc = inheritedPropertyDescriptors( f, 1 );
     74 // returns { 'beep': {...}, ... }
     75 ```
     76 
     77 </section>
     78 
     79 <!-- /.usage -->
     80 
     81 <section class="notes">
     82 
     83 ## Notes
     84 
     85 -   In contrast to the built-in `Object.getOwnPropertyDescriptors()`, if provided `null` or `undefined`, the function returns an empty `object`, rather than throwing an error.
     86 
     87 </section>
     88 
     89 <!-- /.notes -->
     90 
     91 <section class="examples">
     92 
     93 ## Examples
     94 
     95 <!-- eslint-disable id-length -->
     96 
     97 <!-- eslint no-undef: "error" -->
     98 
     99 ```javascript
    100 var defineProperty = require( '@stdlib/utils/define-property' );
    101 var inheritedPropertyDescriptors = require( '@stdlib/utils/inherited-property-descriptors' );
    102 
    103 function Foo() {
    104     this.beep = 'boop';
    105     this.a = {
    106         'b': 'c'
    107     };
    108     defineProperty( this, 'baz', {
    109         'value': 'qux',
    110         'configurable': true,
    111         'writable': true,
    112         'enumerable': false
    113     });
    114     return this;
    115 }
    116 
    117 Foo.prototype.foo = [ 'bar' ];
    118 
    119 var obj = new Foo();
    120 var desc = inheritedPropertyDescriptors( obj );
    121 
    122 console.log( desc );
    123 // => { 'foo': {...}, ... }
    124 ```
    125 
    126 </section>
    127 
    128 <!-- /.examples -->
    129 
    130 <section class="links">
    131 
    132 [@stdlib/utils/property-descriptors]: https://www.npmjs.com/package/@stdlib/utils/tree/main/property-descriptors
    133 
    134 </section>
    135 
    136 <!-- /.links -->