Skip to content

Instantly share code, notes, and snippets.

@daronwolff
Last active May 23, 2016 17:03
Show Gist options
  • Save daronwolff/8a1f748a905b0390763087ee52bbcc14 to your computer and use it in GitHub Desktop.
Save daronwolff/8a1f748a905b0390763087ee52bbcc14 to your computer and use it in GitHub Desktop.
Make a revocable function that takes a nice function and returns a revoke function that denies the access to the nice function, and an invoke function it is invokes the nice function until be revoked
var revoke = (function(func) {
var tmp = func;
return {
invoke: function(p) {
tmp(p);
},
revoke: function() {
tmp = null;
}
}
});
var r = revoke(alert);
r.invoke("I am invoked"); // Alert
r.revoke(); // nothing
r.invoke("I am invoked"); // throw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment