Jeff-Lewis / jquery-klass-plugin

Automatically exported from code.google.com/p/jquery-klass-plugin
0 stars 0 forks source link

Is there a way to determine the type of a class instance? #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Is there a means to get the class name from an instance, similar to c#'s 
.GetType() method?

Original issue reported on code.google.com by ravenous...@gmail.com on 25 Apr 2012 at 11:30

GoogleCodeExporter commented 9 years ago
(Sorry for the delay.)

No, but I am working on it. For the moment, classes have no name.

I am making an extension to add classes to namespaces (also called packages). 
But it can still take a few weeks until it is completed.

From your question, I don't clearly understand if you speak about getting the 
name of a class, or getting its type.

What you can do for now:
- to add names to your classes: add a _static object to all the classes with 
the name:
    MyKlass = $.klass({ _static: { name: "MyKlass" }, init:... });
  Then you have: MyKlass.name === "MyKlass"
  But it wont allow you to find a class from it's name. That is what namespace will be for.
- to get the class of an instance:
    klass = instance.init;
  It also works with:
    klass = instance.constructor;

Original comment by jlgr...@yahoo.fr on 12 Jul 2012 at 5:46

GoogleCodeExporter commented 9 years ago
There is now an extension for namespaces. See 
http://code.google.com/p/jquery-klass-plugin/wiki/Namespace

Hopefully, it should cover your needs.

Original comment by jlgr...@yahoo.fr on 16 Jan 2013 at 5:06