[thelist] JavaScript: Why can't this function see...
Keith Gaughan
keith at digital-crew.com
Thu Mar 10 12:08:17 CST 2005
Hershel Robinson wrote:
>>>1 The page there does NOT declare calDiv globally.
>>
>>Wrong.
>>
>>http://www.google.com/search?q=javascript+%22var+keyword%22
>
>
> Line 32 of the file I see at the URL:
>
> http://www.pixelmech.com/rev/calendar-widget_v2.html
>
> is this:
>
> var currentDateInput;
>
> It is NOT:
>
> var currentDateInput, calDiv;
>
> as in Tom's first post. I thus am not seeing this variable being declared
> globally.
You don't need to. Demo:
// Ex 1. Create a local variable
function f()
{
var x = 2;
alert("In: " + x);
}
var x = 1;
alert("Out: " + x);
f();
alert("Out: " + x);
// Ex 2. Create a global variable with a declaration
function f()
{
x = 2;
alert("In: " + x);
}
var x = 1;
alert("Out: " + x);
f();
alert("Out: " + x);
// Ex 3. Create a global variable *without* a declartion.
function f()
{
var x = 2;
alert("In: " + x);
}
f();
alert("Out: " + x);
Et voila.
K.
More information about the thelist
mailing list