Consider I have class
function home {}{
this.door=function(){},
this.tiles=function(){}
}
I have to add some message after it's methods are called using this library called meld js (https://github.com/cujojs/meld/blob/master/docs/api.md#meldafter)
my try
var allMethods = new home();
Object.keys(allMethods).forEach(function(k){
aop.after(Object.prototype,key,function(){
console.log('Dont use me i am old')
});
})
is this a right approach ?
Your approach is correct but you have several errors in your code. First, the
homefunction should have()instead of{}:Second, in your
AOPcode you need to provide the object to theafter()method and not the prototype.(Also you need to use variable
kand notkeysince that's the one defined in theforEachmethod)If you'll run one of the methods you'll get the wished output.