Last active
May 23, 2016 17:03
-
-
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
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
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