Seems this was an ideal time for a can of Pepper Spray to be in the glove box next to your gun. Gun in one hand, pepper spray the attacker right in the eye. In this case you had the time to use a less than lethal force defense, along with driving away. pepper spray is not always the choice, but it does give you an alternative option.
Spraying pepper spray inside your car
Not really enough details, but going on what we have in the OP, my windows would have already been up when I noticed I was in a bad neighborhood. The OP was able to drive away and all ended well enough but, if that was the case why was a guy able to get in the window in the first place. No better starting place than being aware of your surroundings and reacting appropriately. However if you find yourself in that bad situation and since you can never tell if someone has a concealed weapon or not, if some guy caught me off guard and was in my car window demanding money and threatening me, and I stuck my gun in his chest the words "go ahead and do it" would never have made it out of his mouth, it would have already been done. I do not endorse vigilantism, but if someone is upon you threatening you with money or you life, that IS the appropriate time to defend yourself. I am not sure what some guys are waiting on. I guess some people have the mentality they need to be badly injured before defending themselves, or possibly they are more afraid of their states laws than of the BG, which is just sad and thank God I live in Texas.
I was not there, and in an internet post you can never give all the details and since I was not there I don't want to come across as, "this is exactly what I would have done" because I don't know that, it wasn't me. I guess I just have the mentality that if someone is upon me threatening me with my money or my life, that is not someone I will trust to NOT harm me even if he gets what he wants. I refuse to allow some BG to have that kind of decision to make over me. That is not to say it could not happen, the scenarios, are endless, but I refuse to allow my son to grow up without me because I handed the decision of, weather I live or die over to some scumbag.