I believe you could this via the REST API.
To edit a layer within a feature service: ArcGIS REST API
The thing to note here is that these kinds of calls allow you to redefine everything about a feature service/layer within a feature service, so it's easy to mess something up. I'm not sure what domain JSON looks like exactly, but you should be able to get JSON for a feature layer, edit the domains on it, and post it using the above call.
edit- I should say that I don't believe there's a JS API wrapper around that REST call, but you can use esri/Request to make the request.
Retrieving data ...