How can I listen for a result of socket.on in another function?

I have a standard socket.io function like this :

function listen() {
    socket.on("event", function (data) {

        //return data ????

    });
}

I want to get the result of this function in another external function like this :

App.listen(function(data) {
    //getting the result of listen() when a event is trigerred
});

How should I go about doing this ?

Like other events socket.on doesn't work like that. You can only capture the arguments, and not the return value.

App.value = null;
App.set_value = function(value){
    this.value = value
};

function listen() {
    socket.on("event", function (data) {

        App.value = data;
        //or
        App.set_value(data);
        //Last two calls will work
        //return data ???? will not work

    });
}

Alternatively you can do this.

function listen(App) {
    socket.on("event", function (data) {

        App.value = data;

        //or
        App.set_value(data);
        //Last two calls will work
        //return data ???? will not work

    });
}

listen(App)

If you need to continue a callback chain of events, or asynchronous operations then you can do this.

App.do_something = function(data, func){
    AsyncFunction(data, func);
};
function listen() {
    socket.on("event", function (data) {

        App.do_something(data, function(data){
            //Using async data.
        });

    });
}

listen(App);

If you are using Express(or some other framework) there might be other alternative ways to accomplish this.

Thanks for your reply, it helped me to build my own solution.

Here is what I did :

App.on = function(callback) {
    App.socket.on(this.reference, callback);
}

And I call it like a simple listener :

App.on(function(data) {
    console.log(data);
});

Simply pass a callback function from App.on, pass this function to socket.on, and do whatever you want in this function from App.on