Javascript function hooks

后端 未结 7 1011
孤街浪徒
孤街浪徒 2020-12-24 15:17

EDIT: OK, I believe the following solutions are valid:

  1. Use the jQuery AOP plugin. It basically wraps the old function together with the hook into a function

7条回答
  •  抹茶落季
    2020-12-24 15:56

    Here's what I did, might be useful in other applications like this:

    //Setup a hooking object
    a={
        hook:function(name,f){
            aion.hooks[name]=f;
        }
    }a.hooks={
        //default hooks (also sets the object)
    }; 
    
    //Add a hook
    a.hook('test',function(){
        alert('test');
    });
    
    //Apply each Hook (can be done with for)
    $.each(a.hooks,function(index,f){
        f();
    });
    

提交回复
热议问题