Is it possible to get the name of an anonymous JavaScript function?

Viewed 189

Is it possible to get the name of an anonymous function that declared as follows?

var F = function(){};

At first sight, the answer is no, but apparently the browsers know and hold the function name:

var F = function(){};
var x = new F();
console.log(x.constructor);   // function F()

(Firefox)

var F = function(){};
var x = new F();
console.log(x);    // F {}

(Chrome)

Is this name somehow accessible? I need it mainly for error logging, so the solution doesn't have to be cross-browser.

Edit for clarification:

I'm getting an objects from external code that I need to know their types, therefore obvious answers like using another declaration ways are not what I'm searching.

1 Answers
Related