Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
¿Cómo ejecutar código no desde una cadena usando la función?

¿Cómo ejecutaría código que no fuera de una cadena? Aquí hay un ejemplo:

 var ready = false; executeWhen(ready == true, function() { console.log("hello"); }); function executeWhen(statement, code) { if (statement) { window.setTimeout(executeWhen(statement, code), 100); } else { /* execute 'code' here */ } } setTimeout(function(){ready = true}, 1000);

¿Puedo usar eval(); ? No lo creo, creo que eso es solo para cuerdas.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Lo llamas con code() .

También debe cambiar la statement a una función, por lo que obtendrá un valor diferente cada vez que la pruebe.

Y cuando llamas a executeWhen() en setTimeout() , tienes que pasar una función, no llamarla inmediatamente, lo que provoca una recurrencia infinita.

 var ready = false; executeWhen(() => ready == true, () => console.log("hello")); function executeWhen(statement, code) { if (!statement()) { window.setTimeout(() => executeWhen(statement, code), 100); } else { code(); } } setTimeout(function() { ready = true }, 1000);

about 4 years 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 vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!