Skip to content

Files

Latest commit

55afe3b · Apr 1, 2017

History

History

function-name

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 31, 2017
Jan 1, 2017
Nov 13, 2016
Aug 6, 2016
Jan 1, 2017
Apr 1, 2017

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'