Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.java.* > Newsgroup comp.lang.javascript

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2012, 08:38 PM
Gene Wirchenko
Guest
 
Posts: n/a
Default Stupid JavaScript Trick of the Day: Variable Misdeclaration

Dear JavaScripters:

Laugh or cry depending on which side of the fence you are on.

I had a problem with an XMLHttpRequest object not working right.
readyState did not exist. Oh? Remember that I am still learning this
and am adapting code so there was the very real possibility that I had
overlooked something about setting up the object. It turned that that
I had overlooked something, just not something specific to the object.

I put in some checking to see the object variable's value and
nullness. Well, it did get assigned properly. Had I declared it
properly? Oh, yes.

OK, now what about where it is used? What? It is undefined?
Unfortunately, I had also declared it improperly.

It was supposed to be a global and was declared as such.
Unfortunately, I was following someone else's code so I did not notice
that I had also declared it locally in the function that set up the
object.

Happy Canada Day (July 1), Independence Day (July 4), some other
excuse for a good time (about now).

Sincerely,

Gene Wirchenko
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 07-02-2012, 09:52 PM
Tim Streater
Guest
 
Posts: n/a
Default Re: Stupid JavaScript Trick of the Day: Variable Misdeclaration

In article <6d04v7hag5nipt5n8696rsp77d5bu0diop@4ax.com>,
Gene Wirchenko <genew@ocis.net> wrote:

> I had a problem with an XMLHttpRequest object not working right.
> readyState did not exist. Oh? Remember that I am still learning this
> and am adapting code so there was the very real possibility that I had
> overlooked something about setting up the object. It turned that that
> I had overlooked something, just not something specific to the object.
>
> I put in some checking to see the object variable's value and
> nullness. Well, it did get assigned properly. Had I declared it
> properly? Oh, yes.
>
> OK, now what about where it is used? What? It is undefined?
> Unfortunately, I had also declared it improperly.
>
> It was supposed to be a global and was declared as such.
> Unfortunately, I was following someone else's code so I did not notice
> that I had also declared it locally in the function that set up the
> object.


I take it that you only need one of these at once, then.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Reply With Quote
  #3 (permalink)  
Old 07-02-2012, 10:12 PM
Gene Wirchenko
Guest
 
Posts: n/a
Default Re: Stupid JavaScript Trick of the Day: Variable Misdeclaration

On Mon, 02 Jul 2012 22:52:47 +0100, Tim Streater
<timstreater@greenbee.net> wrote:

[snip]

>I take it that you only need one of these at once, then.


Yes, the global. It is the sort of mistake that I would not make
on my own, but when I do not fully understand the code that I am
adapting -- part of why I am adapting it -- errors can occur.

Sincerely,

Gene Wirchenko
Reply With Quote
  #4 (permalink)  
Old 07-03-2012, 04:09 PM
Gene Wirchenko
Guest
 
Posts: n/a
Default Re: Stupid JavaScript Trick of the Day: Variable Misdeclaration

On Tue, 03 Jul 2012 13:39:49 +0100, Tim Streater
<timstreater@greenbee.net> wrote:

>In article <6174v758q932srbnus4ghml7kssgkhpk6v@4ax.com>,
> Gene Wirchenko <genew@ocis.net> wrote:
>
>> On Mon, 02 Jul 2012 22:52:47 +0100, Tim Streater
>> <timstreater@greenbee.net> wrote:
>>
>> [snip]
>>
>> >I take it that you only need one of these at once, then.

>>
>> Yes, the global. It is the sort of mistake that I would not make
>> on my own, but when I do not fully understand the code that I am
>> adapting -- part of why I am adapting it -- errors can occur.

>
>OK. In my case I could have more than one httprequest running at once,
>so I left it as a variable local to my encapsulation function, thus:


I may change it. I am still experimenting.

[snip]

Sincerely,

Gene Wirchenko
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 08:21 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.