再看JavaScript异步编程这本书,然后看到了一段代码var webSocketCache = {};function openWebSocket(serverAddress, callback) { var socket; if (serverAddress in webSocketCache) { socket = webSocketCache[serverAddress]; if (socket.readyState === WebSocket.OPEN) { callback(); } else { socket.onopen = _.compose(callback, socket.onopen); }; } else { socket = new WebSocket(serverAddress); webSocketCache[serverAddress] = socket; socket.onopen = callback; }; return socket;};书中说 var socket=openWebSocket(url,function(){ socket.send('Hello,server!'); });这样会使代码崩溃,不解。。在返回值之前调用回调函数为什么会使代码崩溃。希望大大们能帮我解释解释
添加回答
举报
0/150
提交
取消
