Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3460338
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:13:02+00:00 2026-05-18T10:13:02+00:00

In jquery scripts i often see functions called like this: var somefunction = function(){

  • 0

In jquery scripts i often see functions called like this:

var somefunction = function(){
  $(this).doseomething()
}

$(someelement).click( somefunction );

Inside somefunction this seams to refer to the the clicked element. If the braces are used to call the function this does not refare to the clicked element.

Personally i don’t like it. I like to see if something used in my code is a function or not. I prefere to pass this as argument. This is how i done it until now:

var somefunction = function($clickedLink){
  $clickedLink.doseomething()
}

$(someelement).click(function(){ somefunction($(this)) });

Why can i access the refared element if i don’t use the braces? And is it a good practice in general to call functions without braces? Does it has an influence on the performance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:13:03+00:00Added an answer on May 18, 2026 at 10:13 am

    It’s not the braces, it’s that any function used as an event handler, and the way jQuery calls event handlers (same is true in vanilla JavaScript), the context of that function is going to be the element that the event is firing on.

    To be a bit clearer on the other point, you’re not calling the function without parenthesis, you’re passing a reference to the function. For example, this says “here’s the function to run when the event happens”:

    $(someelement).click( somefunction );
    

    The other method you have does the same thing, just with more overhead of an extra anonymous function:

    $(someelement).click(function(){ somefunction($(this)); });
    

    The function() { ... } is what you’re passing to run (it’s an anonymous function, rather than your named one). It’s still not until the click event does somefunction actually get called.


    You can do it either way, but they’re not equivalent, when you pass a function directly, this is the element and the first argument is the event object…which you often need to stop propagation or prevent default behavior correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.