Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

57
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.