Hook Plugin for JavaScript
-
Download files !
-
Add the code inside the body tag.
<script src="mx-hook.js"></script>
-
Start coding freely :)
-
Easily create hooks.
var h = new Hook({ func:function() { console.log('Hook Example 1'); }, args:[], name:'test_hook' }); h.run();
-
Define events within options.
var h = new Hook({ func:function() { console.log('Hook Example 2'); }, args:[], name:'test_hook' }); h.on('run', function() { console.log('Run event.'); }); h.run();
-
Run Hooks.
var h1 = new Hook({ func:function() { console.log('Hook Example 1'); }, args:[], name:'test_hook' }); var h2 = new Hook({ func:function() { console.log('Hook Example 2'); }, args:[], name:'test_hook' }); MXHook.run('test_hook');
-
Remove Hooks
MXHook.remove('testing_hook');
Option Name | Type | Details |
---|---|---|
func | function | Function to be called |
name | string | Hook name |
args | array | Constant arguments to be sent to the job to be called. |
initialize(hook) | function | The function to be executed after adding the hook. |
Method Name | Return Type | Details |
---|---|---|
Hook.getCount | int | The number of times the hook works |
Hook.trigger | Hook | Trigger hook event. |
Hook.on | Hook | Bind hook event. |
Hook.unbind | Hook | Unbind hook event. |
Hook.run(['argument1', 'argumentn']) | Hook | Run hook. |
MXHook.add({/* Options */}) | Hook | Adding hook. |
MXHook.remove(_/** Optional */_'hook_name') | MXHook | Remove hook by name. Note: If no name is sent, removes all hooks. |
MXHook.run(_/** Optional */_'hook_name') | Hook | Run hooks by name. Note: If no name is sent, stopped all hooks. |
MXHook.get('hook_name') | Hook | Get hooks by name. |
Event Name | Details |
---|---|
beforerun | This function is executed every time before the hook runs. |
run | This function is executed every time after the hook runs. |
callback[ret, hook] | Callback event. |
Error | Class | Details |
---|---|---|
Invalid argument was sent for adding hook. | HookInvalidAddArgs | If a value other than object type is entered while adding the hook, you will get this error message. You can get help from the examples above when adding hooks. |
Hook function not defined correctly. | HookIsNotFunction | The hook has to be defined as a function. The reason for encountering this error is to define a real function. |