Hi everyone,
    I have question here. Recently I am coming into another open source 
project, which uses angular and socket.io. I am very impressed by how 
powerful and expressive those two combines. But there is piece of code that 
confuses me. In the angular-sockio-io.js module:

> /*
>
>  * angular-socket-io v0.0.2
>
>  * (c) 2013 Brian Ford http://briantford.com
>
>  * License: MIT
>
>  */
>
>
>> 'use strict';
>
>
>> angular.module('btford.socket-io', []).
>
>   factory('socket', function ($rootScope, $timeout) {
>
>     var socket = io.connect();
>
>     return {
>
>       on: function (eventName, callback) {
>
>         alert(1);
>
>         socket.on(eventName, function () {  
>
>           var args = arguments; // 1
>
>           //alert(args.length);
>
>           $timeout(function () {
>
>             callback.apply(socket, args); // 2
>
>           }, 0);
>
>         });
>
>       },
>
>       emit: function (eventName, data, callback) {
>
>         socket.emit(eventName, data, function () {
>
>           var args = arguments;
>
>           $rootScope.$apply(function () {
>
>             if (callback) {
>
>               callback.apply(socket, args);
>
>             }
>
>           });
>
>         });
>
>       }
>
>     };
>
>   });
>
>  

And it is used like this in controller.js:
 

> //controller.js   
>
socket.on("event", function(data) {
>
>       $scope.data[data.id] = data;
>     });
>
>
>
So my questions are as follows:
1. In line 1, should the arguments number always be zero?  But it seems 
that it always get one argument.
2. In line 2, the signature of the 'callback' is clearly different from the 
one used in controller. My guess is that the angular may put some wrapper 
around the original callback to get a new callback, but I am still 
wondering how exactly this works out.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to