Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Function assigned to var wants extra semicolon

Reply
Thread Tools

Function assigned to var wants extra semicolon

 
 
Lawrence San
Guest
Posts: n/a
 
      10-18-2006
According to a JavaScript debugger (Firebug), and to a JS lint, this is
fine:

function recalc(){deriv = 6;} [more code here]

But, if I've assigned the function to a variable like this:

var bells = function recalc(){deriv = 6;} [more code here]

.... then both the debugger and the lint report an error, saying there's
a missing semicolon after the close-curly-brace. They say I should do
this:

var bells = function recalc(){deriv = 6;}; [more code here]

They must be right, because the code works the second way but not the
first way. But why? Isn't a close-curly-brace supposed to be sufficient
to indicate the end of a statement? Usually, if you put a semicolon
after a close-curly-brace like this:

function recalc(){deriv = 6;}; [more code here]

....the lint complains "Warning: empty*statement or*extra*semicolon".
But if the beginning of the statement includes a variable assignment,
it wants the extra semicolon at the end. Why?

--
Lawrence San
Cartoon Stories for Thoughtful People:
<http://www.sanstudio.com>
 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      10-18-2006
Lawrence San said:
>
>According to a JavaScript debugger (Firebug), and to a JS lint, this is
>fine:
>
> function recalc(){deriv = 6;} [more code here]
>
>But, if I've assigned the function to a variable like this:
>
> var bells = function recalc(){deriv = 6;} [more code here]
>
>... then both the debugger and the lint report an error, saying there's
>a missing semicolon after the close-curly-brace. They say I should do
>this:
>
> var bells = function recalc(){deriv = 6;}; [more code here]
>
>They must be right, because the code works the second way but not the
>first way. But why? Isn't a close-curly-brace supposed to be sufficient
>to indicate the end of a statement? Usually, if you put a semicolon
>after a close-curly-brace like this:
>
> function recalc(){deriv = 6;}; [more code here]
>
>...the lint complains "Warning: empty statement or extra semicolon".
>But if the beginning of the statement includes a variable assignment,
>it wants the extra semicolon at the end. Why?


One is a function definition, which logically ends with a closing bracket.
The other is an assignment statement.
The fact that what you have on the right-hand side of this
assignment happens to be a function definition doesn't change that.


--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bit check using function check(var,pos) ((var)&(1<<pos)) prati C Programming 0 10-27-2012 05:25 PM
Help with semicolon inside a write() function RogerF Javascript 1 10-02-2007 05:51 PM
Cookies: semicolon vs. semicolon-space Peter Michaux Javascript 3 12-11-2006 04:43 PM
VB2005 - BugProof - The variable 'var' is either undeclared or was never assigned JulioNobre ASP .Net 0 09-26-2006 01:10 PM
Threads.. Session var lost, App var ok Alvin Bruney ASP .Net 1 12-02-2003 01:56 AM



Advertisments