I'm having an issue accessing the scope of a module level variable from within a function inside of said module. See below...
var socketio = require('socket.io');
var socket = socketio.listen();
var myCustomModule = require('./lib/mycustommodule')('http://mysite:8080');
socket.on('connection', function connection(socket) {
socket.emit('message', {data:"test1"}); <====THIS WORKS
socket.on('init', function init(data) {
socket.emit('message', {data:"test1"}); <====THIS WORKS
refreshMyCustomModule();
});
});
var refreshMyCustomModule = function() {
socket.emit('message', {data:"test1"}); <=====THIS DOESN'T WORK
myCustomModule.beginSomeAsyncTask(function(data) { <======THIS DOESN'T WORK
socket.emit('message', {data:"test2"}); <========THIS DOESN'T WORK
});
};
Looking at the sample above. When I call my refreshMyCustomModule function suddenly socket and myCustomModule become undefined. I've also tried using this as well as setting up a var self = this.
I've written a bunch in javascript on the client but when coding in node.js it seems like scoping is different and I just can't crack this nut.