0

I'm trying to get the name of a function dynamically

exports.LOAD = function() {
  try {
    // DO SOME WORK
  } catch (e) {
    console.log(e);
    EX_JS_ALERT.ALERT("OOPS SOMETHING WENT WRONG");
    EX_JS_ERROR.ERROR(e.toString(), location.pathname);
  }
} 

So at the moment all functions are created either like this or like

function LOAD() {
  try {
    // DO SOME WORK
  } catch (e) {
    console.log(e);
    EX_JS_ALERT.ALERT("OOPS SOMETHING WENT WRONG");
    EX_JS_ERROR.ERROR(e.toString(), location.pathname);
  }
} 

so (location.pathname) gives the page that its on is there anyway I can get the line? or the "function LOAD"

I saw this

var func1 = function() {}

var object = {
  func2: function() {}
}

console.log(func1.name);
// expected output: "func1"

console.log(object.func2.name);
// expected output: "func2" 

is there any way I can replace func1.name with function.name or this.name to send the function its currently in?

Manish Balodia
  • 1,863
  • 2
  • 23
  • 37
Custard
  • 49
  • 1
  • 9
  • What problem are you trying to solve? Functions declared as `function()` instead of `function fName()` don't have a name property, they're anonymous functions. But there are not alot of cases where the function name matters, so which problem are you trying to solve by knowing the function name? – Shilly Jul 31 '18 at 08:43
  • so we have around 3000 EX_JS_(NAME).js files so dynamically we send the error to our email server. So we can find it before the user. We have gotten it down to the page Im trying to get as much information as I can in the Catch. the e.toString() doesnt carry the entire error like in the console. – Custard Jul 31 '18 at 08:47
  • it doesnt give the function name gives the value of everything in the function – Custard Jul 31 '18 at 10:48

0 Answers0