I came to stackoverflow to find the answer to this question since I have found it to be a fabulous source of knowledge. And there indeed appears to be a lot of answers to this question but I am unable to find one that fits my needs.
After years of working on server side programming, I finally decided that a lot of stuff could be done a lot more quickly on the client side so I decided to jump more enthusiastically into JavaScript.
Since I was working for a customer I decided to try and do best practices right off the bat. So I searched for how to emulate namespaces and read up on "Classes" and so I evolved code as in what follows
var ABC {}; // Create a namespace.
ABC.Object1 = function() {} // A constructor for a class
ABC.Object1.prototype = {
someMethod: function() {}
}
So now I can create an object by var o = new ABC.Object1() abd I can call o.someMethod()
But then I wanted to write s debug() method and in it I wanted to log some debug information. I am using Chrome for the browser and when I break and trace I can see that "o" is of type "ABC.Object1" but I can't find anyway where my method can determine the "class" name. I keep putting class in quotes because I know that there really is no such thing as a Javascript class. But it seems I should be able to do it. I noticed some methods use the name of the constructor Function, so I changed the constructor to
function ABC.Object1(){}
but that is bad syntax because there should be no period there.
I don't have that many classes, so I am happy to redo all the constructors but I'd like advice on how to do it so I can determine the name of the class and maintain the namespace idea. By calling everything under namespace ABC (not the real name, but illustrative I minimize the chance of a naming conflict.
One person suggested putting in the constructor "this.name = "ABC.Object1" and that would work but that is too hokey and certainly wouldn't scale.
Any advice much appreciated.