javascript - Why is it always runs the callback function as TRUE? -
javascript - Why is it always runs the callback function as TRUE? -
there function callback:
function _isbanned(iduser, idfriend, callback){ redis.sismember("user.friend_tmp:" + idfriend, iduser, function(err, friends){ console.log(friends); if(friends == 0) { homecoming callback(true); } callback(false); }); }
function call:
isbanned(data.from, data.to, function() { // body }
despite fact console.log (friends);
equal 1, function executed, , transfers command // body ...
you calling callback regardless of value of if
test. passing true
in 1 case , false
in other case, calling callback in both cases. then, within callback aren't paying attending arguments passed callback no different behavior in 2 cases.
perhaps code should this:
isbanned(data.from, data.to, function(banned) { if (banned) { // 1 action here } else { // different action here } }
javascript
Comments
Post a Comment