I'm no expert but during one game I was watching they explained that if the dribbler gets ahead of the defender (closer to the basket) then it is a foul on the defender. If the dribbler isn't closer to the basket and pushes off the defender it's a foul on the dribbler.