IE11 WebSocket对象onopen:预期对象

时间:2018-11-07 13:44:28

标签: javascript jquery internet-explorer-11

我正在使用websockets在聊天系统中工作。不久,我意识到它在IE11和Edge中效果不佳。因此,我已经开始使用ES2015而不是ES2016为那些浏览器开发单独的JS文件。不幸的是,IE11一直让我发疯似的烦扰我!

在以下代码中,我在Socket.onopen上遇到对象预期错误:

function Chat(){
    /* Settings */
    this.serverHost = window.location.host;
    this.serverPort = 9300;
    this.socket = false;
}

Chat.prototype.connect = function(){
    var Socket = new WebSocket('wss://'+this.serverHost+'/myws/');
    this.setSocketEvents(Socket);
    this.socket = Socket;
}

Chat.prototype.setSocketEvents = function(Socket){
    Socket.onopen(function() { // Object expected error
        // some code..
    });
}

控制台日志:套接字

{binaryType: "blob", bufferedAmount: 0, CLOSED: 3, CLOSING: 2, CONNECTING: 0, extensions: "", onclose: null, onerror: null, onmessage: null, onopen: null, OPEN: 1, protocol: "", readyState: 0, url: "wss://mywebsite..."}

控制台日志:typeof(Socket)

object

我在这里迷路了。有人能告诉我怎么回事吗?

0 个答案:

没有答案