我有一个这样的对象:
window.socketFunctions = {
waybillDocCreated: function(data){
console.log(data);
}
}
比我想在套接字中使用它
if (window.socketFunctions){
for (var name in window.socketFunctions){
socket.on(name, window.socketFunctions[name]);
}
}
像这样:
socket.on('suitable', function(data){
var badge = $('#suitableBadge');
if(badge.length){
badge.addClass('label-danger');
badge.addClass('label');
var count = parseInt(badge.html() || 0);
badge.html(++count);
}
});
在这段代码之后,它将我的函数保存为waybillDocCreated(),但是.on('suitable')将其保存为匿名