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