Skip to content

Latest commit

 

History

History

function-name

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Function Name

Determine a function's name.

Usage

var functionName = require( '@stdlib/utils/function-name' );

functionName( fcn )

Returns the name of a function.

var name = functionName( Math.sqrt )
// returns 'sqrt'

If provided an anonymous function, the function returns an empty string or the string "anonymous".

var name = functionName( function(){} );
// returns '' || 'anonymous'

If provided a value which is not a function, the function throws a TypeError.

try {
    // throws...
    var name = functionName( 'beep' );
} catch ( err ) {
    console.error( err );
}

Notes

Examples

var functionName = require( '@stdlib/utils/function-name' );

var bool = functionName( Math.sqrt );
// returns 'sqrt'

bool = functionName( Float64Array );
// returns 'Float64Array'

bool = functionName( Buffer );
// returns 'Buffer'

bool = functionName( Date );
// returns 'Date'

bool = functionName( String );
// returns 'String'

bool = functionName( Boolean );
// returns 'Boolean'

bool = functionName( Function );
// returns 'Function'

bool = functionName( Number );
// returns 'Number'

bool = functionName( function foo(){} );
// returns 'foo'

bool = functionName( function(){} );
// returns '' || 'anonymous'