This is probably best asked by stating an example.
The out-of-the-box Query widget contains a variable called tempResultLayer. I have another custom widget which would like to access this layer directly once it's been created by the query. I could go through map.getLayer(), but it seems there's no predictable layerId to reference it with, as the layerId appears to be generated on the fly with each query. The custom widget needs to collect an attribute value from each of the features returned by the query. (Alternatively, if there's a more straightforward way of accomplishing this without customizing the Query widget itself, I'm more than open to suggestions.)