JavaScript: Creating a Custom Callback Function

From The Travis van der Font Wiki
Jump to: navigation, search
This concept uses jQuery. A native example needs to be created.
test_example({par1:1, par2:2, watchEvent:'#dom1'}, function ()
{
    $('#test').submit();
});

function test_example(arguments, callback)
{
    if (arguments)
    {
        if (arguments.par1)
        {
            // ...
        }

        // ...
    }
    
    $(test_example.watchEvent).click(function ()
    {
        if (callback && typeof callback === 'string')
        {
            window[callback](arguments);
        }
        
        if (callback && typeof callback === 'function')
        {
            callback(arguments);
        }
    });
}