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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:52:06+00:00 2026-05-19T11:52:06+00:00

I was looking over the jQuery to better understand how it works. The constructor

  • 0

I was looking over the jQuery to better understand how it works. The constructor basically just calls

new jQuery.fn.init

I was wondering what is the point of having the init inside jQuery’s prototype? Wouldn’t defining init() as part of the jQuery object itself serve the same purpose?


Basically I would like to know why jQuery’s init function is located at jQuery.fn.init() and not jQuery.init()

Are there people doing this:

jQuery('a').eq(0).hide().init('div').slideToggle(); //?
  • 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-19T11:52:07+00:00Added an answer on May 19, 2026 at 11:52 am

    EDIT: Upon re-reading I don’t think this answers your question, but it might be useful for someone’s better understanding of how jQuery works anyway so I’m leaving it.


    What is going on is that jQuery() is being defined as jQuery.fn.init() which is another way to say jQuery.prototype.init() which is the selector function! What this means is that no one would call jQuery.fn.init() or jQuery.init() because jQuery() IS .init()!

    What?

    Let’s look at the piece of code you’re talking about:

    // Define a local copy of jQuery
    var jQuery = function( selector, context ) {
            // The jQuery object is actually just the init constructor 'enhanced'
            return new jQuery.fn.init( selector, context );
        },
    

    In the comments it says just what I said, but more briefly. But this is just the local copy of jQuery… however, if you go to line 908 (of version 1.4.4) at the end of the self-executing function you’ll see:

    // Expose jQuery to the global object
    return (window.jQuery = window.$ = jQuery);
    
    })();
    

    …which means that this local jQuery becomes the global jQuery. So? So… this local jQuery was actually jQuery.fn.init() right? So what is init()? If you look from lines 100 to 208 you’ll see that it’s the selector method. What’s the selector method? It’s that method you use all the time to find tags, ids, classes… $('#id'), jQuery('.class'), $('ul li a')… the selector function!

    So no one would ever call jQuery.init('div') because it’s a verbose version of jQuery('div') after that assignment. And remember the jQuery.fn is exactly the same as saying jQuery.prototype so really all that part is doing is assigning .init() as a method of the prototype of the jQuery object. I.E. a jQuery plugin.

    Phew, that was a mouthful. I hope this makes sense, and if anyone has any corrections in case I misinformed in any part of this lengthy explanation please let me know.

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

Sidebar

Related Questions

I am looking over csipsimple app - uses sip calls, registers. I also found
I'm pretty new to Ruby. I've tried looking over the online documentation, but I
I've been looking over the jQuery docs and it indicates that .load is a
I just started looking into jQuery yesterday, before this I programmed in only PHP.
I'm looking to write a function that mimics the ajax calls from the jQuery
Looking over the magento 1.5 schema I cannot seem to figure out how a
I have been looking over the internet for a while about this, but it
I have been looking over this code for the past hour, I cant see
I was looking over the code for qunit. My question is why would you
I have a little / weird behaviour here and Im looking over internet and

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.