-
-
Save TimBlock/83ffeec6461f95f81fa8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 withBoxUnlocked(body) { | |
var closed = box.locked; | |
if (!closed) return body(); | |
box.unlock(); | |
try{ | |
return body(); | |
} finally{ | |
box.lock(); | |
} | |
} | |
withBoxUnlocked(function() { | |
box.content.push("gold piece"); | |
}); | |
try { | |
withBoxUnlocked(function() { | |
throw new Error("Pirates on the horizon! Abort!"); | |
}); | |
} catch (e) { | |
console.log("Error raised:", e); | |
} | |
console.log(box.locked); | |
// → true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment