Skip to content

Files

Latest commit

dc79bf4 · Nov 16, 2016

History

History

function-name

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Nov 16, 2016
Nov 13, 2016
Aug 6, 2016
Nov 16, 2016
Oct 3, 2016

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'