0

I have function like this

var getData = function(){
console.log('test');
}

I call it like getData()

I want to get the name of function inside that.

I tried this

arguments.callee.caller.toString()

but i get this error

Error: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them

How can i fix that

user3214546
  • 6,523
  • 13
  • 51
  • 98
  • If you call it like this `getData()` don't you already know that function name is `getData`? – dfsq May 12 '15 at 05:45
  • @dfsq actually i have code which i want to put inside al functions which will call the same function in different locations – user3214546 May 12 '15 at 05:49
  • You must remove the sentences "use strict" to access that method. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee#Why_was_arguments.callee_removed_from_ES5_strict_mode.3F – Walter Chapilliquen - wZVanG May 12 '15 at 06:03
  • @wZVanG i tried that and then tried console logging and it gave me full function for angular controller rather than getData – user3214546 May 12 '15 at 06:24
  • @user3214546 that depends on where you are calling the function in "angular". I think you should put the code "angular" – Walter Chapilliquen - wZVanG May 12 '15 at 06:35
  • You are trying to get the name of **anonymous function**. You can change it into **named function expression** ( `var getData = function getData(){ ... } `) first and get function name by calling `arguments.callee.name`. There quite a lot of ways also [link](http://stackoverflow.com/questions/2648293/javascript-get-function-name). – themyth92 May 12 '15 at 09:45

0 Answers0