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

200
Views
¿Javascript actualiza la propiedad en los resultados del objeto para actualizar todas las propiedades?

Estoy acostumbrado a la sintaxis de php y parece que no puedo entender por qué no puedo resolver mi problema con algo tan simple... así que aquí va. (Probablemente estoy pasando por alto algo realmente estúpido, pero en este punto es como un toro en un paño rojo)

Mi código :

 n_machines = global.get("n_machines"); endtime = []; running = []; time_left = []; types = ["delayed_output_timer","startup_timer"]; timer = {}; for(i = 0 ; i < types.length ; i++){ key = types[i]; //loop through parameters of timer and set default values for(m_num = 0; m_num < n_machines; m_num ++) { endtime[m_num] = 0; running[m_num] = false; time_left[m_num] = 0; } timer[key] = { endtime: endtime, running : running, time_left : time_left }; } timer.delayed_output_timer.running[0] = "TESTING"; test = timer['delayed_output_timer'].running[0]; msg = {payload:[timer,test],topic:"timer"}; return msg;

Cuando emito este código, esto devuelve un objeto no solo con el timer.delayed_output_timer.running[0] cambiado, sino también con el objeto timer.startup_timer.running[0] cambiado.

¿Qué estoy haciendo mal aquí? No quiero cambiarlo a una matriz. Quiero entender por qué y cómo cambiar 1 de estos arreglos de objetos... ¿no ambos?

También tenga en cuenta que estoy fuera del ciclo cuando lo estoy cambiando y tengo el mismo problema cuando intento cambiar el timer["delayed_output_timer"].running[0] = "TESTING" Aquí está el resultado. (está en la consola roja del nodo, pero eso no debería importar)

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

0

Probablemente debería mover las variables endtime , running y time_left al alcance del ciclo. De lo contrario, si los mantiene globales, cada temporizador usa ese único objeto global declarado en la parte superior.

 n_machines = global.get("n_machines"); types = ["delayed_output_timer","startup_timer"]; timer = {}; for(i = 0 ; i < types.length ; i++){ endtime = []; /// moved here running = []; time_left = []; key = types[i]; ...
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!