在 sockets.find()语句后面的代码中,未执行console.log(" AFTER")语句
io.sockets.on('connection', function (socket) {
var this_socket = socket;
socket.username = null;
socket.gameSessionName = null;
socket.update_usernames = false;
sockets.push(socket); // sockets is AN ARRAY
socket.on('loaded', function (data) {
var previous_socket;
socket.username = data.username;
socket.status = 'BROWSE_PLAYERS'; // WAIT_FOR_ACCEPT, PLAYING
console.log("BEFORE");
previous_socket = sockets.find (function(s) {
return false;
});
console.log("AFTER"); // THIS IS STATEMENT IS NOT EXECUTED
....
如果socket.find()代码如下所示进行注释,则会打印console.log(" AFTER")语句。
// previous_socket = sockets.find (function(s) {
// return false;
// });
看起来 sockets.find(...)语句有副作用。如何解决这个问题。