STOP YELLING AT ME!

...kidding.

On Thu, Nov 5, 2009 at 10:38 AM, Jan Kassens <[email protected]> wrote:

> *
> You can embed the name of the class in the class itself, like:
>
> var MyClass = new Class({
>  name: ‘MyClass’,
>  method: function(){
>  console.log(this.name);
>  }
> });
>
>
> or iterate over all variables in window. This doesn’t work with classes
> that are not in the window space (like Fx.Tween for instance) and is not the
> fastest solution, but might be enough for your case:
>
> Class.getClassName = function(obj){
> for (name in window){
>  if (window[name] == obj.constructor) return name;
>  }
>  return null;
> };
>
> var MyClass = new Class({
>  method: function(){
>  console.log(Class.getClassName(this));
>  }
> });
>
>
> Jan
>
>
> *
> On 05.11.2009, at 15:52, Sam wrote:
>
>
> I want to throw an Exception and tell user what caused exception in a
> form:
>
>  Class::Method
>
> Method name can easily be obtained from:
>
>  arguments.callee
>
> and then processing returned string.
>
> How to get class name inside method?
>
> I create classes next way:
>
> var MyClass = new Class({
>  ...
>  method: function()
>  {
>    console.log( 'Want to output class name here.');
>  },
>  ...
> });
>
>
>

Reply via email to