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