A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: f = function() or function f ()

  1. #1
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509

    f = function() or function f ()

    Hi- I've been away from flash for a while, and have just written a quick game, to test my skills...

    One thing i have forgotten/missed:

    What is the difference between these two:
    code:

    function f() {
    // do somthing
    }


    code:

    f=function() {
    // do something
    }

    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  2. #2
    Member
    Join Date
    Nov 2004
    Location
    Pasig City, Philippines
    Posts
    68
    AFAIK, there is almost no difference between them. The only difference that I notice about them is this:
    You can only declare functions from other reference (timeline or object/array) using the latter form:
    code:
    _global.myFn = function()
    {
    // codes
    }


    or
    code:
    myObject.myFn = function()
    {
    // codes
    }


    and not
    code:
    function myObject.myFn ()
    {
    // codes
    }


    Furthermore, the functions declared in the second form can be declared using var:
    code:

    var myFn = function()
    {
    // codes
    }

    Therefore, the second form is advantageous.
    "Life is unfair... but beautiful."

    Scarlette Krimson
    [email protected]

  3. #3
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509
    Yes, I wrote out about 200 lines of code in two sessions and noticed that I had used the two different syntaxes, yet everything was working.

    I usually use the second, I recall.

    Thanks!
    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    another difference, functions defined using

    function functionName() {

    }

    can be called before the function declaration in your code, for example,

    code:

    sayHello();

    function sayHello() {
    trace("hello");
    }



    works, but

    code:

    sayHello();

    sayHello = function() {
    trace("hello");
    };



    doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center