Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

58
Vistas
lambda scoped variable missing on chrome but not on firefox

I have three javascript functions.

rerender(callbackOptional);
releaseEMail_inFolders(eMailId, currentEMailFolderId, callbackOptional);
attachEMail_inFolders(eMailId, futureEMailFolderId, callbackOptional);

I have this variables:

  • eMailId = 123
  • currentEMailFolderId = 100
  • futureEMailFolderId = [101,102]

The eMail 123 is currently in the folder 100. I like to release the eMail from the folder 100 and I like to attach the eMail into folders 101 and 102. Then rerender().

Usually I would write:

attachEMail_inFolders(123, 101);
attachEMail_inFolders(123, 102);
releaseEMail_inFolders(123, 100);
rerender();

Now I tried to use the callbacks in an array (chain) using this code:

var chain=[];
chain.push(rerender);
chain.push(()=>releaseEMail_inFolders(eMailId, currentEMailFolderId, chain.pop()));
for(var i =0; i < futureEMailFolderIds.length;i++) {
    var v = futureEMailFolderIds[i];
    if (typeof v == 'number'){
        chain.push(()=>{
            console.log(v);
            attachEMail_inFolders(eMailId, v, chain.pop());
        });
    }
}
chain.pop()();

Unfortunately I get this error-message in chrome:

 null
 Uncaught futureEMailFolderId of attachEMail_inFolders is undefined!

But in firefox I get this message:

 102
 101

Why does chrome not allow to use variables exclusievly from this scope to be used inside lamdas/functions?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Was indeed a scope problem. Lamdas ignore vars (in chrome only).

I modified the code to avoid lamdas but use functions.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos