获取类名称 如:在不使用属性赋值类名的使用下function treeSearch(){ this.name="rang"; //不允许使用this.className='treeSearch';的情况下}treeSearch.property={ getClassName:function(){ //我在这里怎么获取到treeSearch的名称,并返回 }};求解决方案.... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 javascript是没有真正的类名称或函数名称的,javascript中函数(Function)是以数据的形式存在的,你可以把函数的引用赋值给多个变量。难道说你要取这些变量的变量名么?你的问题应该是要获取类的引用而不是名称,具体怎么做要看实际情况 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.... 感谢,可以了,我把this.constructor.name改为this.constructor.toString(),然后再截取字符串,获取名称就可以... 感谢,可以了,我把this.constructor.name改为this.constructor.toString(),然后再截取字符串,获取名称就可以...这样也可以,还有个更恶心的办法for(var i in window){ if(window[i]==this.constructor){ alert(i); } }万恶的IE 感谢,可以了,我把this.constructor.name改为this.constructor.toString(),然后再截取字符串,获取名称就可以...这样也可以,还有个更恶心的办法for(var i in window){ if(window[i]==this.constructor){ alert(i); } }万恶的IE果然万恶啊,真的可以..... 求解:关于extjs提交表单的两个问题 问个showmodal的问题,超难 遇到困难急求帮助 javascript基础语法问题 Date(); 请问怎么在客户端控制服务器控件Label的显示/隐藏? 求正侧表达式IE5与IE6不同的解决方法(有解马上送分) 请问javascript中能否弹出有三个按钮的对话框,按钮分别为 是,否,取消 打印又一问题,紧急求救! 请问:通过href传递给read.htm的参数,在modify中如何取得(get)? HighChart做的曲线,提示框内容能否加入除x\y以外的内容? 急!jquery获取某行某列的问题
你的问题应该是要获取类的引用而不是名称,具体怎么做要看实际情况
this.name="rang";
}
treeSearch.prototype={
getClassName:function(){
console.log(this.constructor.name);
}
};
treeSearch.prototype.constructor = treeSearch;
var abc = new treeSearch();
abc.getClassName();
我在ie下测试,提示undefined....
感谢,可以了,我把this.constructor.name改为
this.constructor.toString(),然后再截取字符串,获取名称就可以...
感谢,可以了,我把this.constructor.name改为
this.constructor.toString(),然后再截取字符串,获取名称就可以...
这样也可以,还有个更恶心的办法
for(var i in window){
if(window[i]==this.constructor){
alert(i);
}
}
万恶的IE
感谢,可以了,我把this.constructor.name改为
this.constructor.toString(),然后再截取字符串,获取名称就可以...
这样也可以,还有个更恶心的办法
for(var i in window){
if(window[i]==this.constructor){
alert(i);
}
}
万恶的IE
果然万恶啊,真的可以.....