Characterizing separability of function spaces