How to retrieve the constructor’s name in JavaScript?

On Chrome (7.0.544.0 dev), if I do:

function SomeConstructor() { }

var instance = new SomeConstructor();

console.log(instance.constructor.name);

it prints ‘SomeConstructor’…but if SomeConstructor is defined as an unnamed function as you have it, it will print an empty string instead.

If I print instance.constructor it prints the same thing as it does if I print SomeConstructor in the code you have. The instanceof operator need only compare these two values to see that they are equal to be able to return true.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)