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
...
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.
Comments