JavaScript中"Maximum call stack size exceeded"错误解决方法

错误翻译过来就是"超过了最大调用堆栈大小",出现这个错误的原因是因为我进行了递归运算,但是忘记添加判断条件,导致递归无线循环。

先看看我的代码

function getComputedStyle(obj, prop) {
    if(window.getComputedStyle) {
        return getComputedStyle(obj,null)[prop];
    } else if(obj.currentStyle) {
        return obj.currentStyle[prop];
    }
    return null;
}

其中 if 条件里面return的是该函数,所以会一直递归无限循环,导致程序出错

猜你喜欢

转载自blog.csdn.net/Rao_Limon/article/details/90056753