TwelvestoneFlash

Use of ';' with function {};


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
faerieprince
 
2003-01-30

I have seen this style used and ignored in (seemingly) similar situations. Here are two cases that I have seen:

myFunction = function () { // some code };

function myFunction () { // some code }

Do you need to put a ';' after functions? If so, when and why?

Thanks for the advice!

garyalfred
 
2003-01-30

It is never required.

All ";" means is 'end of line', but most parsers assume "}" is an end of line too, so the two in conjuction is just over kill. It is technically correct to add one I guess but not necessary as far as I know.

bit-101
 
2003-01-30

the first one is a statement. you are creating an anonymous function:

function(){....}

and assigning it to a variable. same as if you said

x=10;

the second one is a function definition

function something(){...}

which does not technically need a semicolon.

sakri
 
2003-01-30

I think it's just a convention from other languages that people use, and have included in their flashes without thinking about it twice... like you said, it works, so why bother "fixing" it...

here's an example from java:

public class Semicolon_thing { public static void main(String[] args){ int[] my_array={1,2,3,4} for(int i=0;i<my_array.length;i++){ System.out.println(my_array[i]); } } }

if I save this as Semicolon_thing.java and try to compile it in my command prompt I get:

C:\JAVA_tests>javac Semicolon_thing.java Semicolon_thing.java:3: ';' expected int[] my_array={1,2,3,4} ^ 1 error

if I add the semicolon after the array construct

public class Semicolon_thing { public static void main(String[] args){ int[] my_array={1,2,3,4} for(int i=0;i<my_array.length;i++){ System.out.println(my_array[i]); } } }

and compile....

C:\JAVA_tests>javac Semicolon_thing.java

C:\JAVA_tests>java Semicolon_thing 1 2 3 4

C:\JAVA_tests>

I think I've also seen this in special cases... anonomous constructs or something...

anyway... nothing to loose sleep over k

faerieprince
 
2003-01-30

wow! responses from 3 of the big dogs all within 5 minutes of each other. must be my lucky day k

thank you all for your input and advice. i am glad this is not another esoteric rule within actionscript i had to keep straight.

sakri
 
2003-01-30

nah.. I'm still a chiuhauha next to these guys... k

garyalfred
 
2003-01-30

im gonna have to agree with sak.. he's a chihuahua.. so cute and fluffy. No big dogs here.. just trying to help;

sakri
 
2003-01-30

/wiggles tail vigorously

here's a group of bit-101's though

http://www.protosite.net/crap/pixel_nero.gifhttp://www.protosite.net/crap/pixel_nero.gifhttp://www.protosite.net/crap/pixel_nero.gifhttp://www.protosite.net/crap/pixel_nero.gifhttp://www.protosite.net/crap/pixel_nero.gifhttp://www.protosite.net/crap/pixel_nero.gifhttp://www.protosite.net/crap/pixel_nero.gifhttp://www.protosite.net/crap/pixel_nero.gif

Percival
 
2003-01-30

If you write the function as the latter and then auto format your code it adds in the semicolons and that's probably why you see them for the most part.

In flash 5 switching to normal and back to expert to format your code would put it all on one line.. that was very annoying. k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Use of ';' with function {};