- Object.prototype.getName =function(){
- s =this.constructor.toString();
- if(s.indexOf('function')==-1){
- returnnull;
- }else{
- s = s.replace('function','');
- var idx = s.indexOf('(');
- s = s.substring(0, idx);
- s = s.replace(" ","");
- }
- return s;
- }
- //调试
- functionMyClass(){}
- var x =newMyClass();
- var name = x.getName();
- alert(name);