Answer the question
In order to leave comments, you need to log in
What does the following line mean in nodejs script?
callback = callback || function() {};
User.updateLastOnlineTime = function(uid, callback) {
callback = callback || function() {};
db.getObjectFields('user:' + uid, ['status', 'lastonline'], function(err, userData) {
var now = Date.now();
if (err || userData.status === 'offline' || now - parseInt(userData.lastonline, 10) < 300000) {
return callback(err);
}
User.setUserField(uid, 'lastonline', now, callback);
});
};
Answer the question
In order to leave comments, you need to log in
if the callback function is not given as a parameter when calling updateLastOnlineTime, then inside updateLastOnlineTime will be initialized with a new empty function.
but it would be better to check that the callback is really a function, and not another object, for example. something like that:
function isFunction(fn) {
var obj= {};
return fn && obj.toString.call(fn) === '[object Function]';
}
callback = isFunction(callback) || function() {};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question