获取类名称

kingboyrang 2013-05-07 03:06:04

如:
在不使用属性赋值类名的使用下
function treeSearch(){
this.name="rang";
//不允许使用this.className='treeSearch';的情况下
}
treeSearch.property={
getClassName:function(){
//我在这里怎么获取到treeSearch的名称,并返回

}
};


求解决方案....
...全文
98 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingboyrang 2013-05-07
  • 打赏
  • 举报
回复
引用 5 楼 bbjbepzz 的回复:
[quote=引用 4 楼 wlzwcr 的回复:] [quote=引用 2 楼 bbjbepzz 的回复:] function treeSearch(){ this.name="rang"; } treeSearch.prototype={ getClassName:function(){ console.log(this.constructor.toString()); } }; treeSearch.prototype.constructor = treeSearch; var abc = new treeSearch(); abc.getClassName();
感谢,可以了,我把this.constructor.name改为 this.constructor.toString(),然后再截取字符串,获取名称就可以...[/quote] 这样也可以,还有个更恶心的办法 for(var i in window){ if(window[i]==this.constructor){ alert(i); } } 万恶的IE[/quote] 果然万恶啊,真的可以.....
bbjbepzz 2013-05-07
  • 打赏
  • 举报
回复
引用 4 楼 wlzwcr 的回复:
[quote=引用 2 楼 bbjbepzz 的回复:] function treeSearch(){ this.name="rang"; } treeSearch.prototype={ getClassName:function(){ console.log(this.constructor.toString()); } }; treeSearch.prototype.constructor = treeSearch; var abc = new treeSearch(); abc.getClassName();
感谢,可以了,我把this.constructor.name改为 this.constructor.toString(),然后再截取字符串,获取名称就可以...[/quote] 这样也可以,还有个更恶心的办法 for(var i in window){ if(window[i]==this.constructor){ alert(i); } } 万恶的IE
kingboyrang 2013-05-07
  • 打赏
  • 举报
回复
引用 2 楼 bbjbepzz 的回复:
function treeSearch(){ this.name="rang"; } treeSearch.prototype={ getClassName:function(){ console.log(this.constructor.toString()); } }; treeSearch.prototype.constructor = treeSearch; var abc = new treeSearch(); abc.getClassName();
感谢,可以了,我把this.constructor.name改为 this.constructor.toString(),然后再截取字符串,获取名称就可以...
kingboyrang 2013-05-07
  • 打赏
  • 举报
回复
引用 2 楼 bbjbepzz 的回复:
function treeSearch(){ this.name="rang"; } treeSearch.prototype={ getClassName:function(){ console.log(this.constructor.name); } }; treeSearch.prototype.constructor = treeSearch; var abc = new treeSearch(); abc.getClassName();
我在ie下测试,提示undefined....
bbjbepzz 2013-05-07
  • 打赏
  • 举报
回复
function treeSearch(){ this.name="rang"; } treeSearch.prototype={ getClassName:function(){ console.log(this.constructor.name); } }; treeSearch.prototype.constructor = treeSearch; var abc = new treeSearch(); abc.getClassName();
天际的海浪 2013-05-07
  • 打赏
  • 举报
回复
javascript是没有真正的类名称或函数名称的,javascript中函数(Function)是以数据的形式存在的,你可以把函数的引用赋值给多个变量。难道说你要取这些变量的变量名么? 你的问题应该是要获取类的引用而不是名称,具体怎么做要看实际情况

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧