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