@stdlib/assert-is-inherited-property v0.2.2
isInheritedProperty
Test if an object has an inherited property.
Installation
npm install @stdlib/assert-is-inherited-propertyUsage
var isInheritedProperty = require( '@stdlib/assert-is-inherited-property' );isInheritedProperty( value, property )
Returns a boolean indicating if a value has an inherited property.
var obj = {
'beep': 'boop'
};
var bool = isInheritedProperty( obj, 'beep' );
// returns false
bool = isInheritedProperty( obj, 'hasOwnProperty' );
// returns true
bool = isInheritedProperty( obj, 'bap' );
// returns falseNotes
The function does not throw when provided
nullorundefined. Instead, the function returnsfalse.var bool = isInheritedProperty( null, 'a' ); // returns false bool = isInheritedProperty( void 0, 'a' ); // returns falseValue arguments other than
nullorundefinedare coerced toobjects.var bool = isInheritedProperty( 'beep', 'toString' ); // returns trueNon-symbol property arguments are coerced to
strings.function Foo() { return this; } Foo.prototype.null = true; Foo.prototype[ '[object Object]' ] = true; var obj = new Foo(); var bool = isInheritedProperty( obj, null ); // returns true bool = isInheritedProperty( obj, {} ); // returns true
Examples
var isInheritedProperty = require( '@stdlib/assert-is-inherited-property' );
var bool = isInheritedProperty( {}, 'hasOwnProperty' );
// returns true
bool = isInheritedProperty( { 'a': 'b' }, 'a' );
// returns false
bool = isInheritedProperty( { 'a': 'b' }, 'c' );
// returns false
bool = isInheritedProperty( { 'a': 'b' }, null );
// returns false
bool = isInheritedProperty( null, 'a' );
// returns false
bool = isInheritedProperty( void 0, 'a' );
// returns false
bool = isInheritedProperty( { 'null': false }, null );
// returns false
bool = isInheritedProperty( { '[object Object]': false }, {} );
// returns falseSee Also
@stdlib/assert-has-own-property: test if an object has a specified property.@stdlib/assert-has-property: test if an object has a specified property, either own or inherited.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.