簡體   English   中英

js oop樣式可在chrome中使用,但不能在Firefox中使用

[英]js oop style working in chrome but not in firefox

我有此腳本,它在chrome(和JS在線驗證器)中運行良好,但是firefox拋出此錯誤:

screen.initialize不是函數

這種語法是否不符合標准?

$(document).ready(function() {

    screen = new Screen('t543f3r','user1','screen4',5);
    screen.initialize();

}

這是Screen類:

//Our screen object
function Screen(hashKey,username,screenName,layout) {

    this.hashKey = hashKey;
    this.username = username;
    this.screenName = screenName;
    this.layout = layout;

    //this.cacheRefreshInterval = 1000*60*5;
    this.checkLayoutInterval = 1000*60*5; //check for new cache every 5 minutes

}

    Screen.prototype.initialize = function() {

        var self = this;
        console.log('initializing screen '+this.screenName+' (layout is ['+this.layout+']) on player '+this.username+' using key '+this.hashKey);

        var time = self.checkLayoutInterval;
        setTimeout(function(){self.getValidLayout();}, time);
        console.log('getValidLayout() set for '+time);

    }

    Screen.prototype.getValidLayout = function() {

        var self = this;
        var url = self.findBaseUrl(true) + 'getValidLayout/'+self.hashKey;

        jQuery.ajax({
            async: true,
            url: url,
            success: function(result) {
                console.log('successfully fetched the valid screen layout: ['+result+']');
                if (result != self.layout) {
                    window.location.reload();
                }
            },
            error: function(result) {
                console.log('there was an error fetching the screen layout');
            },
            complete: function() {

                //setup next check
                var time = self.checkLayoutInterval;
                setTimeout(function(){self.getValidLayout();}, time);
                console.log('next getValidLayout() set for '+time);        

            }                            
        });
    }

window.screen是只讀屬性。 分配給它時(因為未將screen聲明為var),該分配將被忽略。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM