Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

How to get class object's name as a string in Javascript?

user-image
Question ajoutée par Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.
Date de publication: 2014/02/02
Mahmoud Elmahdi
par Mahmoud Elmahdi , UX/UI Designer, Web Developer , ikantam.com

Here's couple of answers Answer1 , Answer2 .

Hope that can help.

mohammed Ali Ali
par mohammed Ali Ali , Software Engineer , Elaw

PLease have a look into this link .hope you can find the answer 

http://stackoverflow.com/questions/1249531/how-to-get-a-javascript-objects-class

Hatim Laxmidhar
par Hatim Laxmidhar , Self Employed , The Way It Works

I assume that you are looking to get class name from an object variable.

e.g.

function Foo() {... ... ... ... ... ... ... }

var myFoo = new Foo();

 

Now you have myFoo and what you want is "Foo".

The simple thing that will work here is:

var strClassname = myFoo.constructor.name;

//here strClassname will hold value "Foo" as string

 

There is a very good disussion done for this@

http://stackoverflow.com/questions/1249531/how-to-get-a-javascript-objects-class

 

 

Noor Khan
par Noor Khan , Technical Team Leader , Insightz360

In JavaScript, every object has a constructor property, which contains a Function object, which has a name property, which contains a string

 

obj.constructor.name

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?