I'll assume for the sake of this question that you mean 641px as the width, but I left the innerHeight variable there, too, in case you need it:
// Closure last-height/width
var lastX = window.innerWidth
var lastY = window.innerHeight
function fooOnResize() {
var x = window.innerWidth
var y = window.innerHeight
if (lastX <= 641 && 641 < x) {
$(".foo").removeClass("bar")
}
lastX = x
lastY = y
}
window.addEventListener("resize", fooOnResize)
// Also okay: window.onresize = fooOnResize
The trick is to basically hold the last size in some closure variables, then on resize, you can make your comparison. After you have done the comparison and the work, you store the current x/y as the last ones, for the next resize.