Skip to content

sendmail2krrish/js-hook-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JS Hook System

Installation

<script src="./src/hook.js"></script>

Example of uses

<p id="product-name"></p>
<p id="product-price"></p>

<script>
    function test() {
        var name = document.getElementById('product-name');
        var price = document.getElementById('product-price');

        // Set up the hooks
        Hook.register('_PRODUCT_NAME', function (args) {
            return args + ' Test Category';
        });

        Hook.register('_PRODUCT_PRICE', function (args) {
            return args + 10;
        });
        Hook.register('_PRODUCT_PRICE', function (args) {
            return args + 10;
        });
        Hook.register('_PRODUCT_PRICE', function (args) {
            return args + 10;
        });
        Hook.register('_PRODUCT_PRICE', function (args) {
            return args + 10;
        });


        name.innerHTML = 'Product Name: ' + Hook.call('_PRODUCT_NAME', 'Test Product');
        price.innerHTML = 'Product Price: $' + Hook.call('_PRODUCT_PRICE', 10);
    }

    test();
</script>

Output

Product Name: Test Product Test Category

Product Price: $50