JSFiddle - React, Tailwind, and code Playground
JavaScript
function revocable(f) {
return {
invoke: function () {
return f.apply(this, arguments);
},
revoke : function () {
f = null;
}
};
}
var temp = revocable(console.log);
temp.invoke('1'); // logs
temp.revoke();
temp.invoke('2'); // throws
// Works in FF, apparently Chrome has a bug...
// use with timeout to allow access
// to a fuction for a set period of time