11

I was looking for a way to get name of function passing in parameter

console.clear();
class A{
   test(){


   }
   testCall(fnc:Function){
     console.log(fnc.name); // i want it display test here not empty
     console.log(fnc);

   }
}

var a=new A();
a.testCall(a.test);

you can check this in jsbin http://jsbin.com/loluhu/edit?js,console

3

2 Answers 2

3

I found this is a bug in typescript

you can find solution here TypeScript not providing function name

Sign up to request clarification or add additional context in comments.

Comments

2

You can extend the Function interface as follows:

interface Function {
    name: string;
}

function foo() {}
alert(foo.name);

See here for a fuller explanation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.