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 8856175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:18:01+00:00 2026-06-14T14:18:01+00:00

This is kind of funky. But take a look at the code snippet below

  • 0

This is kind of funky. But take a look at the code snippet below :

$('.classname').bind('click', somefunction);

function somefunction() {
  console.log($(this)); // **displays[<div>,context<div>]**
}

And if I tweak the above to:

$('.classname').bind('click', function(){ somefunction(); });

function somefunction(){
  console.log($(this)); // **displays [Window]**
}

I am not quite sure why ‘this’ assumes two different values depending on how the function is being called back. The thing is, I do need this to be ,context and the function to be called like

function(event){ somefunction(event); }

because I need the event. But not quite sure what’s up here.

Any leads, people?

  • 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-06-14T14:18:02+00:00Added an answer on June 14, 2026 at 2:18 pm

    “I am not quite sure why ‘this’ assumes two different values depending on how the function is being called…”

    That’s exactly how this works in JavaScript. Its value is based on how the function was called.


    You can manually set it to the value you want using .call or .apply.

    $('.classname').bind('click', function(event){ 
                                      somefunction.call(this, event); 
                                  });
    

    Now there’s no need to modify somefunction. By invoking it with .call(), you’re manually setting the this value to whatever you pass as the first argument.

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

Sidebar

Related Questions

This kind of code would normally work in PHP, but since the scope is
I perform this kind of query in my Python code to conn = rdbms.connect(instance=_INSTANCE_NAME,
I have this code regex, which should transform all kind of diffrent urls into
I got some funny but annoying problem. Somehow I toggled this kind of view
Does this kind of code work for other functions (instead of dbmopen) too, which
This kind of query would work perfectly in SQL Server, but it does not
This kind of question may be asked several times but my problem is different.
Im trying to use this kind of iterators, but I have got errors for
Will this kind of code cause memory leak in Android? class MyActivity extends Activity
I must admin this is kind of funny even though I think I understand

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.