Last active
August 29, 2015 13:56
-
-
Save agnaldo4j/8957923 to your computer and use it in GitHub Desktop.
Controlando escopos de variáveis no javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nesta classe, tento mostrar como criar variáveis que são visíveis na hierarquia de escopo do js. | |
Dassa forma, posso mesmo em um escopo de callback do jquery acessar minha referencia do controller e | |
continuar encapsulando a os dados. | |
Para vc que esta usando AngularJS ou qualquer outro framework de js, é possível usar técnicas OO e | |
de SOLID Principles para melhorar a manutenção de seu código js. | |
Para entender melhor, veja como fazer herança em js em: https://gist.github.com/agnaldo4j/5e6715906813c00d0d46, | |
com essa técnica é possível sobrescrever métodos e usar polimorfismo, ou seja fazer um design OO. | |
Próximo estágio e usar o http://pivotal.github.io/jasmine/ para executar testes. | |
//Implementação parcial, da classe apenas de referência | |
TableFilterMonitorController = function(params) { | |
this.filterName = params.filterName; | |
this.criteriaName = params.criteriaName; | |
this.attributeName = params.attributeName; | |
this.controllerName = params.controllerName; | |
this.renderName = params.renderName; | |
this.bindSearch = function() { | |
var controllerReference = this | |
var _inputSearchCriteria = controllerReference.filter.find('.search-query') | |
_inputSearchCriteria | |
.keyup(function() { | |
var _query = _inputSearchCriteria.val() | |
$.ajax({ | |
url: controllerReference.renderName, | |
type: 'POST', | |
dataType: "json", | |
data: "query="+ _query, | |
success: function(data) { | |
controllerReference.getFilter().find('.filterTabela').html(data.result) | |
controllerReference.bindActions() | |
controllerReference.light() | |
} | |
}); | |
}) | |
.click(function(e) { | |
e.stopPropagation() | |
}) | |
} | |
this.ajaxPopuleOptions = function() { | |
var controllerReference = this | |
$.ajax({ | |
url: controllerReference.renderName, | |
type: 'POST', | |
dataType: "json", | |
success: function(data) { | |
controllerReference.getFilter().find('.filterTabela').html(data.result) | |
controllerReference.bindActions() | |
} | |
}); | |
} | |
} | |
TableFilterMonitorController.prototype = new AbstractFilterMonitorController(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment