有没有办法找回在原型中向Event.observe注册的匿名事件处理程序? [英] Is there a way to get back anonymous event handlers that were registered with Event.observe in Prototype?

查看:72
本文介绍了有没有办法找回在原型中向Event.observe注册的匿名事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与遗留代码接口,我有类似这样的东西:

Interfacing with legacy code, and I've got something like this:

Event.observe(some_form, 'submit', [some anonymous function])

我想收回匿名事件处理程序,在Prototype中有一种简单的方法吗?

I'd like to grab that anonymous event handler back out, is there an easy way to do that in Prototype?

推荐答案

这取决于Prototype的版本.从更一般的答案中我以前写过:

It depends on the version of Prototype. From a more general answer I wrote previously:

  • 版本1.5.x:

  • version 1.5.x:

// inspect
Event.observers.each(function(item) {
    if(item[0] == some_form && item[1] == 'submit') {
        alert(item[2]) // [some anonymous function]
    }
})

  • 版本1.6到1.6.0.3(含)(在这里很难)

  • versions 1.6 to 1.6.0.3, inclusive (got very difficult here)

    // inspect. "_eventId" is for < 1.6.0.3 while 
    // "_prototypeEventID" was introduced in 1.6.0.3
    var submitEvents = Event.cache[some_form._eventId || (some_form._prototypeEventID || [])[0]].submit;
    submitEvents.each(function(wrapper){
        alert(wrapper.handler) // [some anonymous function]
    })
    

  • [当前]版本1.6.1(好一点)

  • [Current] version 1.6.1 (little better)

    // inspect
    var submitEvents = some_form.getStorage().get('prototype_event_registry').get('submit');
    submitEvents.each(function(wrapper){
        alert(wrapper.handler) // [some anonymous function]
    })
    

  • 这篇关于有没有办法找回在原型中向Event.observe注册的匿名事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆