嵌套函数在Mozilla浏览器中不起作用

编码EZ

我在我的应用程序中调用了以下函数

function workerCall() {
    debugger;
    if (typeof (Worker) !== "undefined") {
        var worker = new Worker("Scripts/worker.js");
        worker.onmessage = workerResultReceiver;
        worker.onerror = workerErrorReceiver;
        worker.postMessage({ 'username': Username });
        function workerResultReceiver(e) {
            $('.NotificationCount').html(e.data);
            if (parseInt(e.data) != 0 && currentPage == "Alert") {
                StateFlag = false;
                $('.Notification').show();
                $('.Drildown').each(function () {
                    var temp = this.id;
                    if ($('#' + temp).attr('expand') == "true") {
                        currentTab = temp;
                        StateFlag = true;
                    }
                });
                currentScrollPosition = $('body').scrollTop();
                GetAlerts();
            } else {
                $('.Notification').hide();
            }
        }
        function workerErrorReceiver(e) {
            console.log("there was a problem with the WebWorker within " + e);
        }
    }
    else {

    }
}

该方法将在IE,Chrome中执行,但是在Mozilla中出现错误ReferenceError:未定义workerResultReceiver。如何解决此错误?

羚羊

发生这种情况的原因是您正在引用尚未创建的函数。您需要输入以下内容:

worker.onmessage = workerResultReceiver;
worker.onerror = workerErrorReceiver;

以上

function workerErrorReceiver

行或范围的末尾。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章