Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Pace <bob.pace@gmail.com>2014-07-07 21:48:47 +0400
committerBob Pace <bob.pace@gmail.com>2014-07-07 21:48:47 +0400
commitca709ede5ac0d633f5fec7a6e1e2c40a4db3c48e (patch)
tree64492c7455ef2287c75b27563dca5fec1bc45e2d /lib/__set__.js
parent74dcfece99ff75e36a4ea544885f7aab888a82cf (diff)
added __with__ function according to proposed syntax in issue #29
Diffstat (limited to 'lib/__set__.js')
-rw-r--r--lib/__set__.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/__set__.js b/lib/__set__.js
index 0fa88ac..ad0e5b0 100644
--- a/lib/__set__.js
+++ b/lib/__set__.js
@@ -46,4 +46,21 @@ function __set__() {
};
}
-module.exports = __set__;
+function __with__() {
+ var args = arguments;
+ return function(callback) {
+ if (typeof callback !== "function") {
+ throw new TypeError("__with__ expects a callback function")
+ }
+
+ var undo = __set__.apply(null, args)
+ try {
+ callback();
+ }
+ finally {
+ undo();
+ }
+ }
+}
+
+module.exports = {"__set__": __set__, "__with__": __with__}