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