time-to-botec

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

README.md (4142B)


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