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

310
Views
Javascript console.log(globalThis.object) no está definido pero console.log(globalThis) muestra que existe

Meta
Establezca una variable global en un script y acceda a ella desde otro.

Descripción
En la clase de traductor, tengo un método que carga traducciones personalizadas según el idioma del usuario (tomo el alemán como ejemplo).

 export default class Translator { ... loadTranslation(locale) { const script = document.createElement('script') script.src = path/to/de_custom.js document.body.appendChild(script) console.log('globalThis', globalThis) console.log('loadTranslations', globalThis.tinyMCECustomTranslations) return globalThis.tinyMCECustomTranslations } }

Contenido de de_custom.js :

 function provideTranslations() { globalThis.tinyMCECustomTranslations = { test: 'test de' } } provideTranslations()

console.log('globalThis', globalThis) muestra (tinyMCECustomTranslations existe en la línea 8):

 Window http://localhost:3000/cms/fields/editor/23/de 0: Window http://localhost:3000/cms/fields/editor/23/de ___browserSync___: Object { socketConfig: {…}, socketUrl: "http://localhost:3000/browser-sync", options: {…}, … } "mce-data-1ffd62qa9": 3 provideTranslations: function provideTranslations() regeneratorRuntime: Object { wrap: wrap(innerFn, outerFn, self, tryLocsList), isGeneratorFunction: isGeneratorFunction(genFun), mark: mark(genFun), … } tinyMCE: Object { fire: fire(name, args, bubble), baseURL: "http://localhost:3000/assets/backend", documentBaseURL: "http://localhost:3000/cms/fields/editor/23/", … } tinyMCECustomTranslations: Object { test: "test de" } tinymce: Object { fire: fire(name, args, bubble), baseURL: "http://localhost:3000/assets/backend", documentBaseURL: "http://localhost:3000/cms/fields/editor/23/", … } uidEvent: 7 webpackChunkhybridcms: Array []​ <default properties>​ ...

Pero console.log('loadTranslations', globalThis.tinyMCECustomTranslations) se muestra indefinido. Lo mismo cuando lo intento con window en lugar de globalThis .

¿Alguien tiene una pista para mí? ¿Dónde está el punto que no entiendo tan lejos?

about 4 years ago · Juan Pablo Isaza
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!