Created
June 3, 2014 21:24
-
-
Save ih2502mk/eb06da4cbf87e708d5e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////-------- | |
function decor(fn, errorHandler) { | |
return function() { | |
try { | |
return fn.apply(null, arguments); | |
} | |
catch(e) { | |
errorHandler(e); | |
} | |
}; | |
} | |
////-------- | |
function a(b, c) { | |
if (b > 6) { | |
throw new Error("aaaaa"); | |
} | |
return b + c; | |
} | |
var decorated_a = decor(a, function(e){ | |
console.log("Handled elsewhere!"); | |
}); | |
console.log(decorated_a(1, 4)); | |
console.log(decorated_a(7, 4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment