Why can't my code access this variable?

Nik Weiss

I'm trying to build an extension for another program using an SDK. The code is written in JavaScript.

I am loading in an external library (Highcharts) using the SDK's built-in requireJS functionality.

However when I try to access Highcharts, via the Highcharts variable, the browser tells me it is undefined.

I tried console.log(this) to my code, after it should have been loaded, and you can see the output below, in the image. Highcharts seems to have been loaded. When I try console.log(EPCMPROXY) I get that object, but when I try console.log(Highcharts), I get undefined. If I open the console of the browser window, and manually type in Highcharts, it returns the object. Am I doing something wrong, or referencing Highcharts incorrectly? How is it possible that I can access the one object (EPCMPROXY) but not the other (Highcharts) when they are in the same scope?

Code:

console.log(this);
console.log(Highcharts);
console.log(EPCMPROXY);  //some var generated by the page, used as example here

Output of console.log(this):

j {owner: f, init: function, componentDeleted: function, beforeUpdate: function, afterUpdate: function…}
    $:function ()
        arguments : null
        caller : null
        length : 0
        name : ""
        prototype : Object
        __proto__ : function ()
        [[FunctionLocation]] : combined_static_includes_1.jsversion=20170105152024:25
        [[Scopes]]:Scopes[2]
            0 : Closure (a)
            1 : Global
                $ : function (e,i)
                AsyncHandleJavascriptError : function AsyncHandleJavascriptError(a)
                EPCMPROXY : Object
                ES6Promise : Object
                Highcharts : Object

Output of console.log(Highcharts):

undefined

Output of console.log(EPCMPROXY):

Object
  ...

Console Screenshot

Nik Weiss

The problem is that when the line "console.log(Highcharts)" is executed, it wasn't actually loaded yet (due to problems with my requireJS set-up). The reason I could see it when I executed "console.log(this)" is, as dsfq pointed out, that it shows objects that might have been loaded later, since it is run asynchronously. The little blue "i" icon, which can be seen in the screenshot, is actually a tooltip from Chrome which states: "Value below was evaluated just now".

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why can't I access my objects member variable?

Why can't useEffect access my state variable in a return statement?

Why can't I access variable in my dictionary of JSON object?

why can't I access the variable in my class. python

Why I can't access my script variable from class?

Why can't I access my variable in the widget?

Why can't I remove the intermediate variable in my code?

Why isn't my variable initialized in this code?

Why can't I access this global variable?

Why method can't access class variable?

Why can't I access my private variable inside a function in PHP?

Why can't my subclass access a protected variable of its superclass, when it's in a different package?

Why i can't access my variable declared in package from sub declared in the same package in Perl?

Why can't my class access its own privately declared variable of another object

Why can't pass my variable to applescript?

Why can't the console find my variable?

Why can't kohana find my Variable

Why can I not access my local variable in my ngAfterViewInit function?

Why I can't access to Tss variable declared in assembly from this C code?

Why can't my global variable be called in my function?

How can i access my Status variable in this code?

Why can't my code run in Visual Studio Code?

I can't find a way to access a variable in my html template

Can't figure out why my code won't render

I can't access the "Root" of my Kivy code

I can't access my javascript code because of infinite prompts

Why I can't access to a png image into a folder of my project?

Why can't this global function access my global object?

My Jenkins on CentOS7 can't access...why?