- 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);
【转】js取对象名称
最新推荐文章于 2023-01-05 22:39:17 发布