Add removeHook method.

- Removes a previously attached hook.
- Must be the SAME function to unregister.
This commit is contained in:
T. Thiery 2015-10-10 23:38:05 +02:00
parent 2f781dab81
commit 05a84c6630

View File

@ -104,3 +104,12 @@ window.addHook = function(event, callback) {
else else
_hooks[event].push(callback); _hooks[event].push(callback);
} }
// callback must the SAME function to be unregistered.
window.removeHook = function(event, callback) {
if (typeof callback !== 'function') throw('Callback must be a function.');
if (_hooks[event]) {
_hooks[event].splice(_hooks[event].indexOf(callback), 1);
}
}