Hooks


Hooks in javascript are very similar to the hooks in the Codoforum Hook class in PHP.

Adding a hook

You can add a new hook, by using the CODOF.hook.add method

CODOF.hook.add('call_me', function() {

   console.log('I was called');
});

Calling a Hook

You can call a hook, by using the CODOF.hook.call method.

CODOF.hook.call('call_me');

When this line runs, 'I was called' will be logged into the console.
All hooks will be called with the hook name 'call_me' in the order there were added.

Passing arguments

You can pass arguments while using the CODOF.hook.call method.

For example.

CODOF.hook.call('call_me', 'hey, I called you!');

Now, all the functions defined by CODOF.hook.add method can use this argument.


CODOF.hook.add('call_me', function(called) {

    if(called) console.log(called);
    else console.log('I was called');
});
© CODOFORUM 2024. All Rights Reserved.