我开始使用模式观察器来开发我的jQuery应用程序,但真诚地,我不明白这种模式的好处。jQuery和观察者模式
例子:
myfunctions = {
first_function: function() {
alert('This is the first function');
},
second_function: function() {
alert('This is the second function');
}
};
现在,为什么这个方法:
$(document).bind({
'first_function': myfunctions.first_function,
'second_function': myfunctions.second_function
});
$('button').bind('click', function() {
$(document).trigger('first_function');
});
是比这更好:
$('button').click(function() {
myfunctions.first_function();
});
为什么在开始理解之前就开始使用它? –