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