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