mootools
One thing that I've always disliked about the jQuery JavaScript framework is its syntax for adding event listeners to elements. The way to add a click event to an element using jQuery is:
关于jQuery JavaScript框架,我一直不喜欢的一件事是将事件侦听器添加到元素的语法。 使用jQuery向元素添加click事件的方法是:
$('#myElement').click(function() {
//do work
});
I love OOP so the above code tells me that a click is being triggered, not that it's going to add a listener to the element. There's nothing wrong with jQuery using that syntax; I simply don't prefer it. What I do when I need to work with jQuery is Moo-ify its syntax when I can. Here's how you can implement MooTools' "addEvent" syntax in MooTools.
我喜欢OOP,所以上面的代码告诉我,单击已触发,而不是向元素添加侦听器。 使用该语法的jQuery没错; 我根本不喜欢它。 当我需要使用jQuery时,我要做的就是在可能的情况下Moo-ify其语法。 这是在MooTools中实现MooTools的“ addEvent”语法的方法。
jQuery JavaScript (The jQuery JavaScript)
jQuery.fn.addEvent = jQuery.fn.bind; //updated
We add the "addEvent" function to the jQuery.fn object. Pretty simple.
我们将“ addEvent”函数添加到jQuery.fn对象。 很简单
用法 (The Usage)
$(document).ready(function() {
$('#myElement').addEvent('click',function(){ alert('w00t'); });
});
Looks a lot like MooTools, no? If you like jQuery's syntax of .click() type events, read my post: Implementing jQuery-Like Event Syntax in MooTools
看起来很像MooTools,不是吗? 如果您喜欢jQuery的.click()类型事件的语法,请阅读我的文章: 在MooTools中实现类似jQuery的事件语法
mootools