Which fat a cookie recipe calls for will give you some clue as to how old the recipe is. Because margarine and shortening only entered the food chain in the last 100 plus years or so, this question is a relatively new one!
Flavor and cost aside, the purpose of using fat in cookies is to tenderize them and to extend their keeping qualities. The major functional difference between butter and margarine vs. shortening is that butter and margarine are about 80% fat, whereas shortening (and lard) are 100% fat.
Most of the 20% non-fat portion of butter and margarine is water; and water plus the physical action of making dough acts upon the proteins in flour to form gluten. Some gluten formation keeps your cookies from falling apart; but too much will make your cookies tough. So a cookie made with 100% fat will be more tender.
Fat also affects the texture of the cookie. Because shortening has a higher melting point than either butter or margarine, a cookie made with it will spread out less when it bakes. A cookie made with shortening will be cakier in texture than one made with butter or margarine. (This is also why some recipes call for you to chill the dough or the cookies before baking, to keep them from spreading.)
Remember that margarine and shortening are man-made, and as such are not the nutritional equivalent of butter. For reasons of both health and flavor, my personal preference for any cookie recipe is unsalted butter.