Example:
attempt(function () {
JSON.parse();
}).
fail(function (e) {
console.error(e);
});| 'use strict'; | |
| function attempt(fn) { | |
| return Object.create({ | |
| 'fail': function (onError) { | |
| try { | |
| fn(); | |
| } | |
| catch (e) { | |
| return onError(e); | |
| } | |
| } | |
| }); | |
| } | |
| exports = module.exports = attempt; |
Either way, I think it's worth trying out if it helps inlining.