HighDots Forums  

Re: Global variable not remembering value

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Global variable not remembering value in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Doug Gunnoe
 
Posts: n/a

Default Re: Global variable not remembering value - 01-21-2008 , 06:26 PM






On Jan 21, 5:08*pm, The Natural Philosopher <a...@b.c> wrote:
Quote:
I am a javascript novice, but surely you need to tell the function
toggleDetail that det is GLOBAL in scope?

Declaring a var like that outside of any function makes it global.

Using the var keyword inside any function makes it local.

Skipping the var keyword altogether will also make it global.

In javascript you could declare and initialize a variable inside a
function like so:

function someFunction(){
det = false;
}

and det will be a global.


Reply With Quote
  #2  
Old   
The Natural Philosopher
 
Posts: n/a

Default Re: Global variable not remembering value - 01-22-2008 , 07:41 AM






Doug Gunnoe wrote:
Quote:
On Jan 21, 5:08�pm, The Natural Philosopher <a...@b.c> wrote:
I am a javascript novice, but surely you need to tell the function
toggleDetail that det is GLOBAL in scope?


Declaring a var like that outside of any function makes it global.

Using the var keyword inside any function makes it local.

Skipping the var keyword altogether will also make it global.

In javascript you could declare and initialize a variable inside a
function like so:

function someFunction(){
det = false;
}

and det will be a global.
Thanks for that.
I guess I should have remembered it all started as some sort of BASIC.
And would therefore break most of the rules of structured programming
before it got round to trying to add them all back again.

With C, there was one slim book, that almost completely defined the
language.

With Javascript, I have a book 4" thick that doesn't even really define
anything. Sigh.


Reply With Quote
  #3  
Old   
Doug Gunnoe
 
Posts: n/a

Default Re: Global variable not remembering value - 01-22-2008 , 04:02 PM



On Jan 22, 6:41 am, The Natural Philosopher <a...@b.c> wrote:

Quote:
Thanks for that.
I guess I should have remembered it all started as some sort of BASIC.
And would therefore break most of the rules of structured programming
before it got round to trying to add them all back again.

With C, there was one slim book, that almost completely defined the
language.

With Javascript, I have a book 4" thick that doesn't even really define
anything. Sigh.
JavaScript can be a pain in the ass at first.

I think it is a very intersting language once you get use to some of
its quirks.

The loose typing and automatic conversion of vars based on context was
an early pain for me. But now I like it.






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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.