Is there a descent way to wrap all methods in an existing javascript object(for example third party library) with try catch so that I can process the exeception errors? Sure, I will expose the methods under a new interface.
Here is what I have in mind for now:(consider it as pseudocode)
var MyInterface = {};
for (var property in thirdPartyLib) {
if ((typeof thirdPartyLib[property]) === 'function'){
MyInterfac[property] = function(){
try {
thirdPartyLib[property](arguments)
}
catch(err){
//do my custom processing
}
}
}
}
//developer use MyInterface object
Just wondering, any better approach or any flaw with my above idea? Thanks.