Javascript reference for undefined property

Using Firefox, while working on the Firefox extension, I constantly get a warning from javascript:

reference to undefined property mySidebar.context.netProgress

I tried several ways to test the value:

if (mySidebar.context.netProgress === undefined) {

and

if (typeof mySidebar.context.netProgress == "undefined") {

and

if (!mySidebar.context.netProgress) {

and

if (mySidebar.context.netProgress == undefined) {

However, the error console in Firefox continues to give me a warning in one line each time, the line in question is the line in which I sent the code from above. Actual verification of the value triggers a warning.

I also set a warning to check the value of mySidebar.context, which is always an object, so I do not get a warning from the parent.

Any ideas?

+5
source share
2 answers

hasOwnProperty()

if (mySidebar.context.hasOwnProperty("netProgress")) {
+3

, Object.prototype.hasOwnProperty(), . , . , , :

if ("netProgress" in mySidebar.context) {
+6

All Articles