Test if an object has a specified method name, either own or inherited.
npm install @stdlib/assert-is-method-in
Alternatively,
- To load the package in a website via a
script
tag without installation and bundlers, use the ES Module available on theesm
branch. - If you are using Deno, visit the
deno
branch. - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umd
branch.
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
var isMethodIn = require( '@stdlib/assert-is-method-in' );
Returns a boolean
indicating if a value
has a specified method name, either own or inherited.
var value = {
'beep': 'boop'
};
var bool = isMethodIn( value, 'toString' );
// returns true
bool = isMethodIn( value, 'beep' );
// returns false
bool = isMethodIn( value, 'bap' );
// returns false
-
The function does not throw when provided
null
orundefined
. Instead, the function returnsfalse
.var bool = isMethodIn( null, 'toString' ); // returns false bool = isMethodIn( void 0, 'toString' ); // returns false
-
Value arguments other than
null
orundefined
are coerced toobjects
.var bool = isMethodIn( 'beep', 'toString' ); // returns true
-
Non-symbol property arguments are coerced to
strings
.function noop() { // Example function... } var value = { 'null': noop }; var bool = isMethodIn( value, null ); // returns true value = { '[object Object]': noop }; bool = isMethodIn( value, {} ); // returns true
var isMethodIn = require( '@stdlib/assert-is-method-in' );
var bool = isMethodIn( {}, 'toString' );
// returns true
bool = isMethodIn( { 'a': 'b' }, 'a' );
// returns false
bool = isMethodIn( { 'a': 'b' }, 'c' );
// returns false
bool = isMethodIn( { 'a': 'b' }, null );
// returns false
bool = isMethodIn( null, 'a' );
// returns false
bool = isMethodIn( void 0, 'a' );
// returns false
bool = isMethodIn( { 'null': isMethodIn }, null );
// returns true
bool = isMethodIn( { '[object Object]': isMethodIn }, {} );
// returns true
@stdlib/assert-has-property
: test if an object has a specified property, either own or inherited.@stdlib/assert-is-function
: test if a value is a function.@stdlib/assert-is-method
: test if an object has a specified method name.
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.
See LICENSE.
Copyright © 2016-2023. The Stdlib Authors.