our JavaScript API doesn't include any inbuilt tools to accomplish something like that so you might consider publishing a geoprocessing service to accomplish the same. it would have to take in an input featureset and write those features to disk on the server.
Here is an example using a feature layer and exporting to a shapefile through a button added to the info window. The export is handled through a geoprocessing service.
Note: it will take about 30-60 seconds for the zipped shapefile to be returned