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

160
Views
La función importada no hace lo que se supone que debe hacer cuando se ejecuta broma

ARCHIVO DE ALMACENAMIENTO DE DATOS:

 let data = { users: [], channels: [], }; // Use get() to access the data function getData() { return data; } // Use set(newData) to pass in the entire data object, with modifications made function setData(newData) { data = newData; } export { getData, setData };

clearV1() ARCHIVO:

 import { getData, setData } from './dataStore'; function clearV1() { let data = { users: [], channels: [], }; setData(data); return {}; } export { clearV1 };

Al ejecutar la función clearV1() en otro, no borra el almacén de datos. Por ejemplo: authRegisterV1 crea un usuario y lo agrega al almacén de datos channelCreateV1 crea un canal y lo agrega al almacén de datos

 authRegisterV1('test1@gmail.com','test123','Firt','Last'); clearV1() authRegisterV1('test2@gmail.com','test123','Firt','Last'); expected output: { users: [ { uId: 1, email: 'test2@gmail.com', password: 'test123', nameFirst: 'Firt', nameLast: 'Last', handle: 'firtlast0', permissionId: 2 } ], channels: [], } wrong output: { users: [ { uId: 1, email: 'test1@gmail.com', password: 'test123', nameFirst: 'Firt', nameLast: 'Last', handle: 'firtlast', permissionId: 1 }, { uId: 2, email: 'test2@gmail.com', password: 'test123', nameFirst: 'Firt', nameLast: 'Last', handle: 'firtlast0', permissionId: 2 } ], channels: [], }

Creo que la implementación de la función clearV1() es correcta, ¿qué otra posible razón podría haber para este error? Importé todas las funciones utilizadas en el archivo de prueba.

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

0

Creo que el problema al que se enfrenta es el hecho de que creó data dentro de ./dataStore y, por lo tanto, no existe en el archivo clearV1() . Otra forma de decirlo es, cuando creó la variable de datos inicialmente, se creó en ./dataStore y solo existe allí. Entonces crea una nueva variable en lugar de actualizar la existente.

Otro problema es que está intentando usar let data = [value] . let crea la variable justo dentro de la función en la que la llamaste, ignorando cualquier variable en el exterior. Como regla general en javascript, al actualizar una variable existente, use [name] = [value] .

Si desea obtener más información, aquí están los documentos de MDN para declaraciones de importación y declaraciones de permiso .

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!