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

308
Views
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
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!