The bayonet was introduced in the late 17th century as a knife (later a short sword) attached to a musket, to enable the musketeer to protect himself when reloading their single-shot weapons. As such, it was something of an "adjunct" weapon to the gun itself. http://en.wikipedia.org/wiki/Bayonet
Anti-cavalry tactics in the late 18th, early 19th century often consisted of musketeers with bayonets "forming square" to resist cavalry charges. These resistances often succeeded, whereas during earlier periods, such as the Middle Ages, soldiers armed with "pole" weapons such as spears were usually at a disadvantage versus cavalry (unless there were compensating features such as rough ground or bad weather), even though these were their "primary" weapons.
What gave soldiers with bayonets (and muskets) their effectiveness? Did the one volley of musket fire sufficiently disorganize the cavalry to give the bayoneters their advantage? Did the presence of muskets force a change in cavalry tactics (e.g. the removal of armor) that favored the musketeer? Were they just better-drilled soldiers than the spear carriers?