Getting The Name Of A Defined Object With A Constructor
I'm trying to get the name of an object and put it in an array after it's defined, I tried doing this code, but the name ended up being undefined any help? function command(categor
Solution 1:
Objects do not have a name or name
property (unless you add one yourself). If you're referring to the variable name that references the object, that is not possible to access.
Solution 2:
Let's say you create an object named "foo":
var foo = new command("category", "help", "callback");
If you want to add foo
to the array cmndlist[category]
, you just need to use this
:
cmndlist[category].push(this.objectName);
And it will work!
Post a Comment for "Getting The Name Of A Defined Object With A Constructor"