>I declared a function in a file called somefile.js as follows:
>>
function foo() {
alert ("yippi!"); }
In HTML-file i'm importing it by adding:
onClick='foo()'
The somefile.js is imported correctly (according to my breakpoints in
FireBug SOME code in the file is reached). Despite of that, as i cause
the
onClick-event to fire, i get the error message: "Function is not
defined".
How can i debug it? As far i can see, it should work. :)
Are you sure that the declaration of foo() is in the global scope and not
inside another function?
Well, i checked for that parentesis-wise a while ago, so yes, i was sure..
Then you got me thinking and i tried to move the function around, just for
the sake of testing. And guess what - it turns out that the function
definition needs to be at the top of the file, before any other code
(except for comments, blanks and other functions, i guess)! That's
extremely surprising!
I'd expect the function definition to be in global scope if it's declared
OUTSIDE of any {}-pair but apparently, it's not sufficient. Problems
solved. Thanks! You were right about being out of scope, even if it didn't
appear that way to me.
--
Regards
Konrad Viltersten