Javascript“构造函数”属性中的错误 - IE 8

时间:2013-10-22 21:07:17

标签: javascript google-chrome internet-explorer-8

我遇到以下代码问题。错误发生在最后一行:

  

返回p_Function.constructor.name +“(”+ v_args +“)”;

当我在Internet Explorer 8上运行它时,该函数返回 undefined()。 Howerver,它适用于谷歌浏览器(返回 FunctionName())。我认为这是“构造函数”属性的问题,但我无法弄清楚如何解决它。我是JavaScript的新手,如果能得到一些帮助,我会很高兴。

提前致谢。

getFunctionExecutionString: function(p_Function){
        var v_args = "";
        if(p_Function.arg) {
            for(var k=0; k < p_Function.args.length; k++) {
                if(typeof  p_Function.args[k] == "string"){
                    v_args += "\"" + p_Function.args[k].replace(/'/g, "") + "\",";
                }
                else{
                    v_args += p_Function.args[k] + ",";
                }
            }
            v_args = trim(v_args,",");
        }

               return p_Function.constructor.name + "(" + v_args + ")";
     }
  };

1 个答案:

答案 0 :(得分:4)

How do I get the name of an object's type in JavaScript?

return p_Function.constructor.toString().match(/function (.{1,})\(/)[1] + "(" + v_args + ")";

示例:

var A = function A(){};
var a = new A();
console.log(a.constructor.toString().match(/function (.{1,})\(/)[1]);