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

解决方案 »

  1.   

    javascript是没有真正的类名称或函数名称的,javascript中函数(Function)是以数据的形式存在的,你可以把函数的引用赋值给多个变量。难道说你要取这些变量的变量名么?
    你的问题应该是要获取类的引用而不是名称,具体怎么做要看实际情况
      

  2.   

    function treeSearch(){
       this.name="rang";
    }
    treeSearch.prototype={
        getClassName:function(){
           console.log(this.constructor.name);
     
         }
    };
    treeSearch.prototype.constructor = treeSearch;
    var abc = new treeSearch();
    abc.getClassName();
      

  3.   


    我在ie下测试,提示undefined....
      

  4.   


    感谢,可以了,我把this.constructor.name改为
    this.constructor.toString(),然后再截取字符串,获取名称就可以...
      

  5.   


    感谢,可以了,我把this.constructor.name改为
    this.constructor.toString(),然后再截取字符串,获取名称就可以...
    这样也可以,还有个更恶心的办法
    for(var i in window){
         if(window[i]==this.constructor){
         alert(i);
         }
         }
    万恶的IE
      

  6.   


    感谢,可以了,我把this.constructor.name改为
    this.constructor.toString(),然后再截取字符串,获取名称就可以...
    这样也可以,还有个更恶心的办法
    for(var i in window){
         if(window[i]==this.constructor){
         alert(i);
         }
         }
    万恶的IE
    果然万恶啊,真的可以.....