Test if an object has an inherited property.
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we’ve built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url]
Test if an object has an inherited property.
bash
npm install @stdlib/assert-is-inherited-property
script
tag without installation and bundlers, use the [ES Module][es-module] available on the [esm
][esm-url] branch (see [README][esm-readme]).deno
][deno-url] branch (see [README][deno-readme] for usage intructions).umd
][umd-url] branch (see [README][umd-readme]).javascript
var isInheritedProperty = require( '@stdlib/assert-is-inherited-property' );
boolean
indicating if a value
has an inherited property
.javascript
var obj = {
'beep': 'boop'
};
var bool = isInheritedProperty( obj, 'beep' );
// returns false
bool = isInheritedProperty( obj, 'hasOwnProperty' );
// returns true
bool = isInheritedProperty( obj, 'bap' );
// returns false
null
or undefined
. Instead, the function returns false
.javascript
var bool = isInheritedProperty( null, 'a' );
// returns false
bool = isInheritedProperty( void 0, 'a' );
// returns false
null
or undefined
are coerced to objects
.javascript
var bool = isInheritedProperty( 'beep', 'toString' );
// returns true
strings
.javascript
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
javascript
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 false