S
Stone Zhong
Hi,
I am learning JavaScript, so please pardon me if my question is naive.
I bought a book "JavaScript The Definitive Guide, 3rd Edition" by
David Flanagan, it is a used book and only cost me $1.
, on page
199-200, there is a sample program like below, instead of getting the
outout the book suggested, Firefox(3.6.3) shows an error: "f.g is not
a function".
I undertand the book is about JavaScript 1.2, is there anything wrong
with the sample?
Thanks,
Stone
var x = "global";
function f() {
var x = "local";
function g() {
alert(x);
}
}
// Display "undefined", f() as not been invoked yet, so
// while the local variable x exists in its call object, it has not
// yet had a value assigned to it.
f.g();
// Calling f() initializes the variable
f();
// Now when we invoke the nested function we obtain the value of
// f's local variable
f.g(); // displays "local"
I am learning JavaScript, so please pardon me if my question is naive.
I bought a book "JavaScript The Definitive Guide, 3rd Edition" by
David Flanagan, it is a used book and only cost me $1.
199-200, there is a sample program like below, instead of getting the
outout the book suggested, Firefox(3.6.3) shows an error: "f.g is not
a function".
I undertand the book is about JavaScript 1.2, is there anything wrong
with the sample?
Thanks,
Stone
var x = "global";
function f() {
var x = "local";
function g() {
alert(x);
}
}
// Display "undefined", f() as not been invoked yet, so
// while the local variable x exists in its call object, it has not
// yet had a value assigned to it.
f.g();
// Calling f() initializes the variable
f();
// Now when we invoke the nested function we obtain the value of
// f's local variable
f.g(); // displays "local"