Skip to content

Instantly share code, notes, and snippets.

@nachoverdon
Last active June 9, 2016 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nachoverdon/fa4e0edbe127a7a9df1c5ec0d6dd3bc2 to your computer and use it in GitHub Desktop.
Save nachoverdon/fa4e0edbe127a7a9df1c5ec0d6dd3bc2 to your computer and use it in GitHub Desktop.
dsafjklañdshj
// He estado mirando un poco el código y he visto que repites bastante el método append en
// _buildModal (y self.$modal también xD).
// La repetición de [i]self.$modal[/i] la puedes apañar con un simple:
// var modal = self.$modal y ya te ahorras unas cuantas letras.
// Lo otro:
self.$modal.$modalcontent.append(self.$modal.$modalmorelbtn);
self.$modal.$modalcontent.append(self.$modal.$modalmorebox);
//...
self.$modal.$modalbox.append(self.$modal.$modaltopbar);
self.$modal.$modalbox.append(self.$modal.$modalcontent);
self.$modal.$modalbox.append(self.$modal.$modalbotbar);
// Lo puedes abstraer en una función y te puede quedar algo así:
function append(destination, element) {
var m = self.$modal;
return m[destination].append(m[element]);
}
append('$modalcontent', '$modalmorelbtn');
append('$modalcontent', '$modalmorebox');
//...
append('$modalbox', '$modaltopbar');
append('$modalbox', '$modalcontent');
append('$modalbox', '$modalbotbar');
// O incluso otros métodos siempre que sigan ese patrón
// (self.$modal.DESTINO.METODO(self.$modal.ELEMENTO)) con algo así:
function method(destination, method, element) {
var m = self.$modal;
return m[destination][method](m[element]);
}
// puedes luego simplificar la función append así:
function append(destination, element) {
return method(destination, 'append', element);
}
//...
//self.$modal.$modalbox.appendTo(self.$modal.$modalbackground);
// ^ antes
// v después
$method('$modalbox', 'appendTo', '$modalbackground');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment