Results 1 to 4 of 4

Thread: Why Doesn't it Work?

  1. #1
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default Why Doesn't it Work?

    Why doesn't:
    Code:
    function () {alert("Test");} ();
    work?
    Are you supposed to put a name
    Code:
    function !!!HERE!!! () {alert("Test");} ();
    ?
    As if you were doing:
    Code:
    function test (stringie) {alert (stringie);}
    ?
    I'm just wondering because sometimes if I want to localize variables I try and use that.

  2. #2
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Code:
    (function(){alert("Test");})();  //this will work
    or as you write it with the whitespace:

    Code:
    (function () {alert("Test");}) ();
    ----

    If you're any interested, I've written a little tutorial on Javascript at:
    http://trinithis.awardspace.com/Java...roduction.html

    It'll cover anonymous functions.
    Last edited by Trinithis; 08-11-2007 at 01:30 AM.
    Trinithis

  3. #3
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Thanks, but was I correct on why?

  4. #4
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    I don't know why it doesn't work without the extra set of parenthesis. Perhaps it's just a matter of syntax rules
    Trinithis

Bookmarks

Posting Permissions

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