简体   繁体   中英

How to identify class in minified Google Closure code?

Using Google Closure inheritance paradigm how can I see whats the class name or how can I otherwise identify the class since object.constructor.name returns "" and is incorrect when minified?

The purpose is to execute code dependent on the implementation of an interface or inherited class. This code is inside of a decorator class which extends Animal , too:

var object = XXX; // of @type {Animal}
switch (object.constructor.name) {
    case 'Dog':
       //...
       break;
    case 'Cat':
       //...
       break;
}

I think this will also work:

switch (object.constructor) {
case Dog:
  ...
case Cat:
  ...
}

or (a little uglier since you can't use switch )

if (object instanceof Dog) {
  ...
} else if (object instanceof Cat) {
  ...
} else if ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM