Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

js error

0 views
Skip to first unread message

Alexandre Jaquet

unread,
Oct 6, 2004, 9:05:01 AM10/6/04
to
Hi I couldn't understand why in my web page when I've an image the page work
and when I delete the image the code doesn't work anymore :

<script type='text/javascript'>
function Go(){return}
</script>
<!-- this line leave an error !-->
<IMG alt="" src="images/SMALL_ABUZ_RECORDS.JPG" align="middle" />

<script type='text/javascript' src='scripts/exmplmenu_var.js'></script>
<script type='text/javascript' src='scripts/menu_com.js'></script>

Daniel Kirsch

unread,
Oct 6, 2004, 9:21:00 AM10/6/04
to

This should work.
You either deleted more than just that line or your js files contain
code, that's based on the image's existence.
Without seeing that code (give a URL) one can only guess.

Daniel

Randy Webb

unread,
Oct 6, 2004, 12:54:07 PM10/6/04
to
Alexandre Jaquet wrote:

> Hi I couldn't understand why in my web page when I've an image the page work
> and when I delete the image the code doesn't work anymore :
>
> <script type='text/javascript'>
> function Go(){return}
> </script>
> <!-- this line leave an error !-->

Yes, as it should.

function Go() {return true}
or
function Go() {return false}


When you use return, you have to return something. Not just return.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Daniel Kirsch

unread,
Oct 6, 2004, 1:02:40 PM10/6/04
to
Randy Webb wrote:
> When you use return, you have to return something. Not just return.

This might be good style but it's not necessary. If you use return only,
the returned value is undefined but it's still a valid script.

Daniel

Dave Anderson

unread,
Oct 6, 2004, 1:20:14 PM10/6/04
to
Randy Webb wrote:
>
> function Go() {return true}
> or
> function Go() {return false}
>
>
> When you use return, you have to return something. Not just return.

Not according to ECMA-262v3, 12.9:

ReturnStatement :
return [no LineTerminator here] Expression(opt);

Semantics
An ECMAScript program is considered syntactically incorrect
if it contains a return statement that is not within a
FunctionBody. A return statement causes a function to cease
execution and return a value to the caller. If Expression is
omitted, the return value is undefined. Otherwise, the
return value is the value of Expression.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Randy Webb

unread,
Oct 6, 2004, 1:21:51 PM10/6/04
to
Daniel Kirsch wrote:

I guess it depends on what you define as a "valid" script. :-)
If you aren't going to return anything, no need to return at all.

Daniel Kirsch

unread,
Oct 6, 2004, 1:39:40 PM10/6/04
to
Randy Webb wrote:
> If you aren't going to return anything, no need to return at all.

Well, if you don't have to return anything but have to return before
reaching the method's end, using just return might be good practice:

function foo(arg) {
if (!arg) return;
// do something();
}

This way, the method will always return undefined.

Of course, you could also write

function foo(arg) {
if (arg) {
// do something();
}
}

But this often makes a script less readable, especially if used with
more if statements.

Daniel

0 new messages