Permalink
Browse files

Make advisor more forgiving when trying to add an aspect to a non-exi…

…stent method
  • Loading branch information...
1 parent 1f8acf7 commit a86c5f67c44f17adb98dea50f33f074d00624a34 @briancavalier briancavalier committed Dec 7, 2011
Showing with 6 additions and 9 deletions.
  1. +6 −9 aop.js
View
15 aop.js
@@ -252,26 +252,23 @@
function addAspectToMethod(target, method, aspect) {
var advisor = Advisor.get(target, method);
- if(advisor) {
- return advisor.add(aspect);
- } else {
- throw new Error('Target does not have method: ' + method);
- }
+ return advisor && advisor.add(aspect);
}
function addAspectToAll(target, methodArray, aspect) {
- var removers, f, i;
+ var removers, added, f, i;
removers = [];
i = 0;
while((f = methodArray[i++])) {
- removers.push(addAspectToMethod(target, f, aspect));
+ added = addAspectToMethod(target, f, aspect);
+ added && removers.push(added);
}
return {
remove: function() {
- for (var i = removers.length - 1; i >= 0; i--) {
- removers[i]();
+ for (var i = removers.length - 1; i >= 0; --i) {
+ removers[i].remove();
}
}
};

0 comments on commit a86c5f6

Please sign in to comment.