SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    syntax question re calling function in an object

    I am learning much from the Simply Javascript book - now in the chapter about events. I have a simpleminded question - when you call an isolated funcition you use parenthesis after the name of the function: e.g. dothisfunction()

    It seems that when the funtion is a method inside of an object you leave out the parenthesis - quoting from page 108 of the book I see:
    link.onclick = wikipediaLink.clickHandler;

    rather than:

    link.onclick = wikipediaLink.clickHandler();

    Am I correct and can anyone explain why?

    Many thanks for any clarification.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Function itself is an object so
    Code:
    link.onclick = wikipediaLink.clickHandler;
    just makes link.onclick and wikipediaLink.clickHandler referencing the same object.

    Code:
    link.onclick = wikipediaLink.clickHandler();
    executes function wikipediaLink.clickHandler and saves its result into link.onclick.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?


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
  •