Last active
July 23, 2016 14:24
-
-
Save friedemannsommer/63cc35ee4b26c7e86729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFunctionName(fn) { | |
if (typeof fn.name === 'string') { | |
return fn.name; | |
} | |
var fnString = fn.toString(); | |
var firstBracket = fnString.indexOf('('); | |
return fnString.substr(9, (firstBracket - 9)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare interface Function extends Function { | |
name:string | |
} | |
function getFunctionName(fn:Function):string { | |
if(typeof fn.name === 'string'){ | |
return fn.name; | |
} | |
let fnString:string = fn.toString(); | |
let firstBracket:number = fnString.indexOf('('); | |
return fnString.substr(9, (firstBracket - 9)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment