I'm kind a new in Javascript and I have this situation: I have a separated javascript file and I created a javascript object in this way:
$(document).ready(function () {
var formasPagamento = {
Cartao: 0,
Crediario: 1,
Vale: 2
};
});
In this same file, I have a function and I want to use this object formasPagamento, but when I try to use it, I get the error that formasPagamento is undefined.
Ex:
function CarregarDetalhesPlanoPagamento(idPosDocPagamento) {
if(idPosDocPagamento == formasPagamento.Cartao){ //undefined here
//do something
}
}
What's the proper way to initializa a "global" variable that can be used in another function?
var formasPagamentooutside of$(document).ready(function () {scopevarand you don't have to move it.