time-to-botec

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

README.md (2547B)


      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 # writablePropertySymbols
     22 
     23 > Return an array of an object's own writable symbol properties.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var writablePropertySymbols = require( '@stdlib/utils/writable-property-symbols' );
     31 ```
     32 
     33 #### writablePropertySymbols( obj )
     34 
     35 Returns an `array` of an object's own writable symbol properties.
     36 
     37 ```javascript
     38 var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
     39 var Symbol = require( '@stdlib/symbol/ctor' );
     40 var defineProperty = require( '@stdlib/utils/define-property' );
     41 
     42 var obj = {};
     43 
     44 if ( hasSymbolSupport() ) {
     45     defineProperty( obj, Symbol( 'a' ), {
     46         'configurable': false,
     47         'enumerable': false,
     48         'writable': true,
     49         'value': 'b'
     50     });
     51 }
     52 
     53 var symbols = writablePropertySymbols( obj );
     54 ```
     55 
     56 </section>
     57 
     58 <!-- /.usage -->
     59 
     60 <section class="notes">
     61 
     62 ## Notes
     63 
     64 -   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.
     65 
     66 </section>
     67 
     68 <!-- /.notes -->
     69 
     70 <section class="examples">
     71 
     72 ## Examples
     73 
     74 <!-- eslint no-undef: "error" -->
     75 
     76 ```javascript
     77 var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
     78 var Symbol = require( '@stdlib/symbol/ctor' );
     79 var writablePropertySymbols = require( '@stdlib/utils/writable-property-symbols' );
     80 
     81 var hasSymbols = hasSymbolSupport();
     82 var symbols;
     83 var obj;
     84 
     85 function Foo() {
     86     if ( hasSymbols ) {
     87         this[ Symbol( 'baz' ) ] = 'qux';
     88     }
     89     return this;
     90 }
     91 
     92 if ( hasSymbols ) {
     93     Foo.prototype[ Symbol( 'bip' ) ] = 'bop';
     94 }
     95 
     96 obj = new Foo();
     97 symbols = writablePropertySymbols( obj );
     98 
     99 console.log( symbols );
    100 ```
    101 
    102 </section>
    103 
    104 <!-- /.examples -->
    105 
    106 <section class="links">
    107 
    108 [ecma-262-for-in]: http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4
    109 
    110 </section>
    111 
    112 <!-- /.links -->