Answer the question
In order to leave comments, you need to log in
What does this JS code do?
$service.Messages = new (Backbone.Collection.extend({
model : $service.Message,
initialize : function() {
var self = this, $el = $("#online"), $users = $("#users");
socket.on("message:get", function (data) {
self.add(data)
});
socket.on("user:added", function ( data, counter ) {
var arr = [];
$el.text( counter );
$users.html("");
for( var i = 0; i < data.length; i++ ) if( data[i] ) {
arr.push("<b>" + data[i].username + "</b>");
};
$users.html( arr.join(", ") );
});
}
}));
$service.Messages.on("add", function( $item ) {
var view = new $service.ViewMessage({model: $item});
$( view.render().el ).prependTo(".message-append");
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question