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

170
Views
¿Qué significa esta gramática {lógica} en JS (no objeto)?

Vi este código en código abierto de reactjs en el archivo github: react.development.js

 { ReactDebugCurrentFrame.setExtraStackFrame = function (stack) { { currentExtraStackFrame = stack; } }; // Stack implementation injected by the current renderer. ReactDebugCurrentFrame.getCurrentStack = null; ReactDebugCurrentFrame.getStackAddendum = function () { var stack = ''; // Add an extra top frame while an element is being validated if (currentExtraStackFrame) { stack += currentExtraStackFrame; } // Delegate to the injected renderer-specific implementation var impl = ReactDebugCurrentFrame.getCurrentStack; if (impl) { stack += impl() || ''; } return stack; }; }

De repente, usa {} sin inicializar para objetar: ¿qué significa esta gramática y cómo se llama esta gramática?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Es un bloque simple.

 { currentExtraStackFrame = stack; }

es equivalente a

 if (true) { currentExtraStackFrame = stack; }

Usar un bloque sin una condición o bucle es bastante extraño, pero está técnicamente permitido. Por qué existe tal código es una buena pregunta, y es porque es el resultado de la transpilación: el código fuente que genera esto es

 const ReactDebugCurrentFrame = {}; let currentExtraStackFrame = (null: null | string); export function setExtraStackFrame(stack: null | string) { if (__DEV__) { currentExtraStackFrame = stack; } } if (__DEV__) { ReactDebugCurrentFrame.setExtraStackFrame = function(stack: null | string) { if (__DEV__) { currentExtraStackFrame = stack; } }; // Stack implementation injected by the current renderer. ReactDebugCurrentFrame.getCurrentStack = (null: null | (() => string)); ...

Cuando el código fuente se transpila a un paquete de JavaScript, si la configuración __DEV__ es verdadera, para transpilar fielmente la existencia de un bloque, parece que if (__DEV__) { simplemente se reemplaza con un bloque simple, que podrían considerar mejor que tener que hacer una verificación de tiempo de ejecución para lo mismo (lo que requeriría un poco de código adicional para enviar a través de la red y un poco de procesamiento adicional para los clientes).

about 4 years ago · Santiago Trujillo 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!