time-to-botec

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

README.md (2427B)


      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 # propertyNamesIn
     22 
     23 > Return an array of an object's own and inherited enumerable and non-enumerable property names.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var propertyNamesIn = require( '@stdlib/utils/property-names-in' );
     31 ```
     32 
     33 #### propertyNamesIn( obj )
     34 
     35 Returns an `array` of an object's own and inherited enumerable and non-enumerable property names.
     36 
     37 ```javascript
     38 var obj = {
     39     'a': 1,
     40     'b': 2
     41 };
     42 
     43 var keys = propertyNamesIn( obj );
     44 // e.g., returns [ 'a', 'b', ... ]
     45 ```
     46 
     47 </section>
     48 
     49 <!-- /.usage -->
     50 
     51 <section class="notes">
     52 
     53 ## Notes
     54 
     55 -   Name order is not guaranteed, as `object` key 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 keys, thus allowing for deterministic extraction.
     56 -   In contrast to the built-in `Object.getOwnPropertyNames()`, if provided `null` or `undefined`, the function returns an empty `array`, rather than throwing an error.
     57 
     58 </section>
     59 
     60 <!-- /.notes -->
     61 
     62 <section class="examples">
     63 
     64 ## Examples
     65 
     66 <!-- eslint no-undef: "error" -->
     67 
     68 ```javascript
     69 var defineProperty = require( '@stdlib/utils/define-property' );
     70 var propertyNamesIn = require( '@stdlib/utils/property-names-in' );
     71 
     72 function Foo() {
     73     this.beep = 'boop';
     74     this.a = {
     75         'b': 'c'
     76     };
     77     defineProperty( this, 'baz', {
     78         'value': 'qux',
     79         'configurable': true,
     80         'writable': true,
     81         'enumerable': false
     82     });
     83     return this;
     84 }
     85 
     86 Foo.prototype.foo = [ 'bar' ];
     87 
     88 var obj = new Foo();
     89 var keys = propertyNamesIn( obj );
     90 
     91 console.log( keys );
     92 // e.g., => [ 'beep', 'a', 'baz', 'foo', ... ]
     93 ```
     94 
     95 </section>
     96 
     97 <!-- /.examples -->
     98 
     99 <section class="links">
    100 
    101 [ecma-262-for-in]: http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4
    102 
    103 </section>
    104 
    105 <!-- /.links -->