请问如何知道当前的this对象所指的函数呢?
用alert(this)输出的是[Object Object],有没有什么方法可以输出当前函数的名称呢?

解决方案 »

  1.   

    一般来说this指的是当前函数或者当前对象
      

  2.   


    function Test() {
    alert(this.constructor);
    }
    new Test();
    看看
      

  3.   

    $.each( this, function(i, n){
      alert( "Name: " + i + ", Value: " + n );
    });这个代码可以遍历this,
      

  4.   

    javascript中的"this"是函数上下文,不是由声明决定,而是由如何调用决定.因为全局函数其实就是window的属性, 所以在顶层调用全局函数时的this是指window对象.
      

  5.   

    this 是“当前的”意思,指的是当前的dom或者对象
      

  6.   


    function funcname(){
     return arguments.callee.toString().substring(8,arguments.callee.toString().indexOf("(")).replace(/^\s*|\s*$/,'');
      }
    alert(funcname())
    一般定义的函数这样可输出函数名,更多的可据此修改。