You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When target is es3 or es5 method inside classes will reduced to anonymous function so it is impossible to get the name of the function, when it is used as parameter.
Function to get the method name
(parameter has type any, because the name attribute is missing in Function type)
/** * Return the name of a given function * @param {Function} functionSource The function * @returns {string} The name of the function */publicstaticGetFunctionName(functionSource: any): string{if(functionSource.name){returnfunctionSource.name;}letfuncNameRegex=newRegExp(/function(.{1,})\(/);letresults=funcNameRegex.exec(functionSource.toString());letresult=results&&results.length>1&&results[1];if(!result){funcNameRegex=newRegExp(/return.([^;]+)/);results=funcNameRegex.exec(functionSource.toString());result=results&&results.length>1&&results[1].split(".").pop();}returnresult||"";}
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
When target is es3 or es5 method inside classes will reduced to anonymous function so it is impossible to get the name of the function, when it is used as parameter.
TypeScript Version: 2.2
Code
Expected behavior: (named function)
Actual behavior: (anonymous function)
Function to get the method name
(parameter has type any, because the name attribute is missing in Function type)
The text was updated successfully, but these errors were encountered: