'How get a value from Object in a function inside itself
I'm trying to change/read a variable from an object through functions, which are inside the same object, but it returns an error that the function doesn't exist.
I still learning JS so, i really don't know how to make this work.
If ideclare all variables and functions as global, it works, but, i wanna make it as a object, so is easyer to work.
Thanks :)
Error like the variables/functions did not exist
The Console:
Command: Baixar = Object.create(Atualizador)
Return: {}
Command: Baixar.AtualizarMangas('nome=tamer')
Return: undefined
Error: atualizador.js:17 Uncaught (in promise) TypeError: this.AtualizarProximoManga is not a function
at atualizador.js:17:9
(anônimo) @ atualizador.js:17
Promise.then (assíncrono)
AtualizarMangas @ atualizador.js:14
(anônimo) @ VM5443:1
Command: Baixar.AtualizarProximoManga()
Error: atualizador.js:26 Uncaught TypeError: Cannot read properties of undefined (reading 'Nome')
at Object.AtualizarProximoManga (atualizador.js:26:85)
at <anonymous>:1:8
AtualizarProximoManga @ atualizador.js:26
(anônimo) @ VM5451:1
The code:
var Atualizador = {
QtdMaxima: 5,
Mangas: [],
Quantidade: 0,
Atual: -1,
QtdAtualizando: 0,
Concluido: false,
AtualizarMangas: function (parametros = '') {
Query = 'action=listarmangasdb';
if (parametros != '') {
Query = Query+'&'+parametros;
}
Response = getExternalAPIResponse(Query);
Response.then(function(result){
this.Mangas = result;
this.Quantidade = this.Mangas.length;
this.AtualizarProximoManga();
})
},
AtualizarProximoManga: function() {
this.Atual += 1;
this.QtdAtualizando += 1;
getExternalAPIResponse('action=updatemangachapters&manga='+this.Mangas[this.Atual]['Nome']).then(
function(result) {
this.QtdAtualizando -= 1;
this.IniciarProximo();
}
)
this.IniciarProximo();
},
IniciarProximo: function() {
if (!this.Concluido) {
if (this.Atual < this.Quantidade) {
if (this.QtdAtualizando < this.QtdMaxima) {
this.AtualizarProximoManga();
}
} else {
this.Concluido = true;
console.log('Mangas Atualizados');
}
}
},
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
