Aspirin inhibits the formation of two main groups of compounds - the prostaglandins and the thromboxanes, by inhibiting the enzyme cyclooxygenase (COX). Here they all are:
The major thromboxane to consider is thromboxane A2. It is produced by platelets, and has the effect of causing vasoconstriction and platelet aggregation. As we would hope, disrupting the production of this substance seems to prevent thrombus formation, and thus heart attacks.
However, there is a complication, and it comes in the form of one of the prostaglandins: prostacyclin (a.k.a. prostaglandin I2). Its normal function is precisely the opposite of thromboxane A2, namely vasodilatation and preventing platelet aggregation. Unfortunately, its production is also prevented by the inhibition of COX, and on the face of things, this seems to present a problem, because any prevention of heart attacks achieved through the inhibition of thromboxane A2 might be cancelled out by the inhibition of prostacyclin.
As it happens, this doesn't really have to be taken into account with aspirin, and the reason for this is interesting. The key fact that rescues the situation is that thromboxane A2 is produced by platelets, whereas prostacyclin is produced by the endothelial cells. Platelets are cellular fragments broken off from from megakaryocytes, and they don't have a nucleus or any DNA whatsoever. This means, like red blood cells, that they are unable to synthesise new proteins. Endothelial cells suffer from no such deficiency. And so, when both are inhibited by aspirin, the endothelium simply produces more prostacyclin, which takes a few hours. On the other hand, the body has to produce entirely new platelets before the thromboxane A2 level rises again, and this takes several aspirin-free days.