Trying to capture response of a async request in dojo/aspect before() event before handing it off to the original method as below:
aspect.before(ecm.model.SearchTemplate.prototype, "_searchCompleted", function(response, callback, teamspace){
var args = [];
if(response.num_results==0 && isValidQuery){
var args = [];
var requestParams = {};
requestParams.repositoryId = this.repository.id;
requestParams.query = query;
Request.invokePluginService("samplePlugin", "sampleService",
{
requestParams: requestParams,
requestCompleteCallback: lang.hitch(this, function(resp) { // success
//call stack doesnt enter this code block before returning params to the original
//function
resp.repository = this.repository;
args.push(resp);
args.push(callback);
args.push(teamspace);
})
}
);
return args; //args is empty as the response is not captured here yet.
}
});
AOPtag, wrapping and reassigning already declared functionality (be it functions or methods) misses any aspect of AOP. Any language which wants to qualify for the latter has to provide abstraction levels for at leastJoinpoint,AdviceandAspect. The use case described by the OP should be referred to as method modification, and JavaScript of cause is well suited for this scenario and could easily provide a completetarget/contextaware toolset of method modifiers likearound,before,after,afterThrowingandafterFinallyviaFunction.prototype.