Click to See Complete Forum and Search --> : Some questions about JavaScript funtions


IrYoKu
12-06-2003, 12:39 PM
Hi,

I am having trouble to find information about some javascript features. I have read the javascript guide and reference at netscape.com with no luck.

They are the next:

- Can I call functions before defining them? (I like to have the most important code at the top of the script). I tried with moz and ie and it works, but I would like to know if the javascript standard permit to do this.

- If I am trying to use an implementation dependant object like "window", if I write the next code:


if (window) {
window.open('hi.html', 'link');
}


This would give an error in a navigator that doesn't have the window object implemented? To say this in another way, the "window.open('hi.html', 'link');" will be checked in any way to know if it is well formed?
I know that in moz this line is not checked because there is no error in the javascript console. But this would mean that only the code on an actually executed branch statements are checked.
I don't have very clear how a javascript is evaluated by a javascript interpreter.

Thanks a lot,
IrYoKu

Khalid Ali
12-06-2003, 01:37 PM
for the first part of your question,not you don't have to declare a function (like you would in C/C++).
The order of functions will not effect,however,make sure the if you use global variables they all must be declared at the begining of the script.

Of course I try to write my functions in the order they are used just for readability purpose....:D