J'ai commencé à utiliser l'observateur de modèle pour développer mes applications jQuery, mais sincèrement, je ne comprends pas les avantages de ce modèle.motif jquery et observateur
Exemple:
myfunctions = {
first_function: function() {
alert('This is the first function');
},
second_function: function() {
alert('This is the second function');
}
};
Maintenant, pourquoi cette méthode:
$(document).bind({
'first_function': myfunctions.first_function,
'second_function': myfunctions.second_function
});
$('button').bind('click', function() {
$(document).trigger('first_function');
});
est mieux que cela:
$('button').click(function() {
myfunctions.first_function();
});
Pourquoi avez-vous commencé à l'utiliser avant de comprendre pourquoi? –