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

  • Home
  • SEARCH
  • 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 8370847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:00:50+00:00 2026-06-09T14:00:50+00:00

I am very new to jquery and javascript. I am looking at how Splunk

  • 0

I am very new to jquery and javascript. I am looking at how Splunk implements some of its modules and got confused.

Here is sample code with a lot of stuff left out.

this.input.bind("focus",this.onInputFocus.bind(this))

this.input refers to a textbox used for a SearchBar. Later, in the file, onInputFocus is declared

onInputFocus: function(evt) {
   ...
   ...
   return true
},

I know the “this.input.bind” statement tells the browser to execute onInputFocus when a person clicks in the textbox but I do not understand .bind(this) at the end of the eventhandler. Please explain to me this notation so I understand what is happening.

  • 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-09T14:00:51+00:00Added an answer on June 9, 2026 at 2:00 pm

    The “outer” bind is binding an event handler to the focus event using jQuery.

    The “inner” Function.bind is creating a function that is bound to a particular context (making this equal to that context when the function is called). This does not require a framework (but does require a modern browser).

    So, in this case, the call to Function.bind is making sure that every time input is focused, the onInputFocus method’s context is set to the current value of this (which is probably the widget/component you’re using). This is necessary because it usually would be the element the event occurred on.

    The MDN article on Function.bind has a good explanation of this.


    To better illustrate how this works, take a simple example:

    HTML:

    ​<button id="test" type="button">Test</button>
    <button id="test2" type="button">Test 2</button>
    <div id="target"></div>
    

    JavaScript:

    var fill = function() {
        $(this).css('background-color', 'yellow');
    };
    /* button#test will be colored yellow */
    $("#test").bind("click", fill);
    
    /* div#target will be colored yellow */
    $("#test2").bind("click", fill.bind($("#target")));
    

    In the first event binding, fill is called and this is set to #test (since that was the element that was clicked).

    In the second, fill is called again, but this is set to #target because of the call to Function.bind inside of the event binding.

    Example: http://jsfiddle.net/GK7L8/

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

Sidebar

Related Questions

im very new to jquery/javascript. So here goes, I found this js code for
New to jQuery/javascript here and looking for a little help. I am writing a
I am very new at jQuery ... I've used Javascript many times and am
I'm very new to Javascript (and jQuery). My JSFiddle really shows the issue in
I'm very new to JQuery, and I'm having some trouble understanding how to do
I am very new to jQuery and javascript programming. I have a program below
I am very new to jquery and need some help. I am trying to
How do you make this code shorter, i'm very new to jquery but i
I am very new to jquery and only basic experience with javascript. I would
(very new to JavaScript jQuery) Can an if statement contain a collection of other

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.