You want the absolute value of the angle difference to be smaller than area or greater than 360-area.
Based on your code, I believe this should work:
var isfacing = function (obj1,obj2,area) {
var toface = direction(obj1.pos,obj2.pos);
var difference = abs(toface - ob1.angle);
ifreturn (difference <= area || difference >= 360 - area) {
return true;
}
return false;;
}
Edit: my first attempt was totally buggy. Sorry.