README.md (2239B)
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 # propertyDescriptors 22 23 > Return an object's own [property descriptors][@stdlib/utils/property-descriptor]. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var propertyDescriptors = require( '@stdlib/utils/property-descriptors' ); 31 ``` 32 33 #### propertyDescriptors( obj ) 34 35 Returns an object's own [property descriptors][@stdlib/utils/property-descriptor]. 36 37 ```javascript 38 var obj = { 39 'a': 1, 40 'b': 2 41 }; 42 43 var desc = propertyDescriptors( obj ); 44 // returns { 'a': {...}, 'b': {...} } 45 ``` 46 47 </section> 48 49 <!-- /.usage --> 50 51 <section class="notes"> 52 53 ## Notes 54 55 - This function differs from the built-in `Object.getOwnPropertyDescriptors()` as follows: 56 57 - If provided `null` or `undefined`, the function returns an empty `object`, rather than throwing an error. 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 propertyDescriptors = require( '@stdlib/utils/property-descriptors' ); 72 73 function Foo() { 74 this.beep = 'boop'; 75 this.a = { 76 'b': 'c' 77 }; 78 defineProperty( this, 'baz', { 79 'value': 'qux', 80 'configurable': true, 81 'writable': true, 82 'enumerable': false 83 }); 84 return this; 85 } 86 87 Foo.prototype.foo = [ 'bar' ]; 88 89 var obj = new Foo(); 90 var desc = propertyDescriptors( obj ); 91 92 console.log( desc ); 93 // => { 'beep': {...}, 'a': {...}, 'baz': {...} } 94 ``` 95 96 </section> 97 98 <!-- /.examples --> 99 100 <section class="links"> 101 102 [@stdlib/utils/property-descriptor]: https://www.npmjs.com/package/@stdlib/utils/tree/main/property-descriptor 103 104 </section> 105 106 <!-- /.links -->