哪些JavaScript库有事件委托?

时间:2021-08-01 00:05:25

I'd like to try out a new JavaScript library. Having used (and loved) jQuery 1.3's "Live" events, I'd prefer the next library I try to have event delegation built in to the event system. Wikipedia's JS Library Comparison falls down on the job here.

我想尝试一个新的JavaScript库。使用(和喜欢)jQuery 1.3的“Live”事件后,我更喜欢下一个库,我尝试将事件委托内置到事件系统中。*的JS图书馆比较在这里工作。

Looks like MooTools is getting it in 2.0. What about the others?

看起来MooTools正在2.0中获得它。其他人怎么样?

I'm making this community wiki. Please help me fill in the list.

我正在制作这个社区维基。请帮我填写清单。

Prototype: no

jQuery: as of 1.3

jQuery:从1.3开始

MooTools: as of 2.0

MooTools:从2.0开始

ExtJS: yes

5 个解决方案

#1


Event delegation is easier than you think.

事件委派比您想象的要容易。

If I find a library without automatic event delegation, I just add a layer to it.

如果我找到没有自动事件委托的库,我只需要添加一个图层。

#2


I'd suggest looking into Prototype. It is listed on SO about as frequently as jQuery and I use it as my JS library for all my projects.

我建议看看Prototype。它在SO上列出与jQuery一样频繁,我将它用作我所有项目的JS库。

I don't believe it has delegates built in but it is a full featured library with all the necessary functionality to add delegates to as needed.

我不相信它内置了代理,但它是一个功能齐全的库,具有根据需要添加代理所需的所有必要功能。

#3


If you love using Jquery but fancy trying something different I would go with mootools, the link to Aarons event delegation plugin plus his tutorial on how to use the original should give you all you need. There is a lot of discussion about which is better at the end of the day its just what you prefer.

如果你喜欢使用Jquery,但想要尝试不同的东西,我会选择mootools,Aarons事件委托插件的链接以及他如何使用原版的教程应该可以满足你所需要的一切。关于哪一个在一天结束时更好的讨论正是你喜欢的。

Mootools is excellent and has some good plugins, you should also check out David Walsh who does a lot of mootools dev and some Jquery. He posts some interesting stuff. http://davidwalsh.name

Mootools很棒并且有一些很好的插件,你还应该看看David Walsh做了很多mootools dev和一些Jquery。他发布了一些有趣的东西。 http://davidwalsh.name

#4


Event delegation is just about hanging event handlers further up the DOM tree. All of the frameworks can/should be able to do that. The handlers should be able to pickup any event that bubbles. The event contains the element that triggered it, and from that the handler can do whatever.

事件委托只是在DOM树上进一步挂起事件处理程序。所有框架都可以/应该能够做到这一点。处理程序应该能够拾取任何气泡事件。该事件包含触发它的元素,并且处理程序可以执行任何操作。

Prototype doesn't have any event delegation sugar native to the library that works like jQuery's $.fn.live, but it is fairly simple to build a function that catches events and does stuff with their target elements.

Prototype没有像jQuery的$ .fn.live这样的库原生的任何事件委托糖,但是构建一个捕获事件并用它们的目标元素做事的函数相当简单。

document.observe('click',function(event){alert(event.element().inspect())})

You can use this to make a clone of jQuery's live pretty easily(I am not saying this will perform well or anything).

您可以使用它来轻松地克隆jQuery的实时(我不是说这会很好地运行)。

live = function(selector,callback){
  document.observe("click",function(e){
    var element = e.element()
    if (!element.match(selector))
      element = element.ancestors().find(function(elem){return elem.match(selector)});
    else
      element = null
    if (element)
      callback.apply(element)
  })
}

You could call it like:

你可以称之为:

live("div",function(){this.setStyle({color:'blue'})})

I guess what I am saying is that event delegation is built in to javascript already. Libraries just add sugar.

我想我所说的是事件委托已经内置于javascript中。图书馆只是加糖。

#5


Ext Js always has I believe.

Ext Js总是让我相信。

#1


Event delegation is easier than you think.

事件委派比您想象的要容易。

If I find a library without automatic event delegation, I just add a layer to it.

如果我找到没有自动事件委托的库,我只需要添加一个图层。

#2


I'd suggest looking into Prototype. It is listed on SO about as frequently as jQuery and I use it as my JS library for all my projects.

我建议看看Prototype。它在SO上列出与jQuery一样频繁,我将它用作我所有项目的JS库。

I don't believe it has delegates built in but it is a full featured library with all the necessary functionality to add delegates to as needed.

我不相信它内置了代理,但它是一个功能齐全的库,具有根据需要添加代理所需的所有必要功能。

#3


If you love using Jquery but fancy trying something different I would go with mootools, the link to Aarons event delegation plugin plus his tutorial on how to use the original should give you all you need. There is a lot of discussion about which is better at the end of the day its just what you prefer.

如果你喜欢使用Jquery,但想要尝试不同的东西,我会选择mootools,Aarons事件委托插件的链接以及他如何使用原版的教程应该可以满足你所需要的一切。关于哪一个在一天结束时更好的讨论正是你喜欢的。

Mootools is excellent and has some good plugins, you should also check out David Walsh who does a lot of mootools dev and some Jquery. He posts some interesting stuff. http://davidwalsh.name

Mootools很棒并且有一些很好的插件,你还应该看看David Walsh做了很多mootools dev和一些Jquery。他发布了一些有趣的东西。 http://davidwalsh.name

#4


Event delegation is just about hanging event handlers further up the DOM tree. All of the frameworks can/should be able to do that. The handlers should be able to pickup any event that bubbles. The event contains the element that triggered it, and from that the handler can do whatever.

事件委托只是在DOM树上进一步挂起事件处理程序。所有框架都可以/应该能够做到这一点。处理程序应该能够拾取任何气泡事件。该事件包含触发它的元素,并且处理程序可以执行任何操作。

Prototype doesn't have any event delegation sugar native to the library that works like jQuery's $.fn.live, but it is fairly simple to build a function that catches events and does stuff with their target elements.

Prototype没有像jQuery的$ .fn.live这样的库原生的任何事件委托糖,但是构建一个捕获事件并用它们的目标元素做事的函数相当简单。

document.observe('click',function(event){alert(event.element().inspect())})

You can use this to make a clone of jQuery's live pretty easily(I am not saying this will perform well or anything).

您可以使用它来轻松地克隆jQuery的实时(我不是说这会很好地运行)。

live = function(selector,callback){
  document.observe("click",function(e){
    var element = e.element()
    if (!element.match(selector))
      element = element.ancestors().find(function(elem){return elem.match(selector)});
    else
      element = null
    if (element)
      callback.apply(element)
  })
}

You could call it like:

你可以称之为:

live("div",function(){this.setStyle({color:'blue'})})

I guess what I am saying is that event delegation is built in to javascript already. Libraries just add sugar.

我想我所说的是事件委托已经内置于javascript中。图书馆只是加糖。

#5


Ext Js always has I believe.

Ext Js总是让我相信。