Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

312
Vistas
Javascript console.log(globalThis.object) is undefined but console.log(globalThis) shows that it exists

Goal
Set a global variable in one script and access it from another.

Description
In the translator class i have a method which loads custom translations depending on the user language (i take german as example).

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
    }
}

Content of the de_custom.js:

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

provideTranslations()

console.log('globalThis', globalThis) shows (tinyMCECustomTranslations exists in line 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>
​
...

But console.log('loadTranslations', globalThis.tinyMCECustomTranslations) shows undefined. Same when i try it with window instead of globalThis.

Does anybody has a hint for me? Where is the point i don't get so far?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda