J'utilise jquery et je suis vraiment frustré par la façon dont j'écris mon code. J'ai commencé à coder en JS et Jquery il y a quelques mois et mon code ressemblait à ceci :
$(document).ready(function(){
$(function(){// a function that applies a plugin to an element});
$(function(){// another function that applies a plugin to an element});
$(function(){// and another function that applies a plugin to an element});
$(function(){// yet another function that applies a plugin to an element});
});
$(function(){//functions applied to certain elements that does not require to be initially loaded})
En fait, ce que je faisais avant, c'était de tout mettre dans le fichier $(document).ready.
et voici comment je code maintenant
function a(){//a function that applies plugin to an element}
function b() {// another function}
$(document.ready(function(){a(); b();});
$(function(){//functions applied to certain elements that does not require to be initially loaded})
une petite amélioration, mais je ne suis pas encore satisfait. Que se passe-t-il si je veux appeler certaines fonctions pour une certaine page seulement ? Y a-t-il des moyens d'accomplir cela ? Et je suis vraiment dégoûté de voir comment mon $(document) devient vraiment énorme quand j'utilise beaucoup de plugins.
Comment faites-vous pour écrire vos fonctions en jquery ?