README.md (2976B)
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 # isInheritedProperty 22 23 > Test if an object has an inherited property. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isInheritedProperty = require( '@stdlib/assert/is-inherited-property' ); 31 ``` 32 33 #### isInheritedProperty( value, property ) 34 35 Returns a `boolean` indicating if a `value` has an inherited `property`. 36 37 ```javascript 38 var obj = { 39 'beep': 'boop' 40 }; 41 42 var bool = isInheritedProperty( obj, 'beep' ); 43 // returns false 44 45 bool = isInheritedProperty( obj, 'hasOwnProperty' ); 46 // returns true 47 48 bool = isInheritedProperty( obj, 'bap' ); 49 // returns false 50 ``` 51 52 </section> 53 54 <!-- /.usage --> 55 56 <section class="notes"> 57 58 ## Notes 59 60 - The function does **not** throw when provided `null` or `undefined`. Instead, the function returns `false`. 61 62 ```javascript 63 var bool = isInheritedProperty( null, 'a' ); 64 // returns false 65 66 bool = isInheritedProperty( void 0, 'a' ); 67 // returns false 68 ``` 69 70 - Value arguments other than `null` or `undefined` are coerced to `objects`. 71 72 ```javascript 73 var bool = isInheritedProperty( 'beep', 'toString' ); 74 // returns true 75 ``` 76 77 - Non-symbol property arguments are coerced to `strings`. 78 79 ```javascript 80 function Foo() { 81 return this; 82 } 83 84 Foo.prototype.null = true; 85 Foo.prototype[ '[object Object]' ] = true; 86 87 var obj = new Foo(); 88 89 var bool = isInheritedProperty( obj, null ); 90 // returns true 91 92 bool = isInheritedProperty( obj, {} ); 93 // returns true 94 ``` 95 96 </section> 97 98 <!-- /.notes --> 99 100 <section class="examples"> 101 102 ## Examples 103 104 <!-- eslint-disable object-curly-newline, object-curly-spacing --> 105 106 <!-- eslint no-undef: "error" --> 107 108 ```javascript 109 var isInheritedProperty = require( '@stdlib/assert/is-inherited-property' ); 110 111 var bool = isInheritedProperty( {}, 'hasOwnProperty' ); 112 // returns true 113 114 bool = isInheritedProperty( { 'a': 'b' }, 'a' ); 115 // returns false 116 117 bool = isInheritedProperty( { 'a': 'b' }, 'c' ); 118 // returns false 119 120 bool = isInheritedProperty( { 'a': 'b' }, null ); 121 // returns false 122 123 bool = isInheritedProperty( null, 'a' ); 124 // returns false 125 126 bool = isInheritedProperty( void 0, 'a' ); 127 // returns false 128 129 bool = isInheritedProperty( { 'null': false }, null ); 130 // returns false 131 132 bool = isInheritedProperty( { '[object Object]': false }, {} ); 133 // returns false 134 ``` 135 136 </section> 137 138 <!-- /.examples --> 139 140 <section class="links"> 141 142 </section> 143 144 <!-- /.links -->