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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:27:21+00:00 2026-06-10T08:27:21+00:00

OK! First of all this question comes from a man who digs too deep

  • 0

OK! First of all this question comes from a man who digs too deep (and posibly get lost) in the jQuery universe.

In my reserch I discovered the jquery’s main pattern is something like this (If needed correction is wellcomed):

(function (window, undefined) {

   jQuery = function (arg) {
      // The jQuery object is actually just the init constructor 'enhanced'
      return new jQuery.fn.init(arg);
   },
   jQuery.fn = jQuery.prototype = {
      constructor: jQuery,
      init: function (selector, context, rootjQuery) {
         // get the selected DOM el.
         // and returns an array
      },
      method: function () {
         doSomeThing();
         return this;
      },
      method2: function () {
         doSomeThing();
         return this;,
         method3: function () {
            doSomeThing();
            return this;
         };

         jQuery.fn.init.prototype = jQuery.fn;

         jQuery.extend = jQuery.fn.extend = function () {

            //defines the extend method 
         };
         // extends the jQuery function and adds some static methods 
         jQuery.extend({
            method: function () {}

         })

      })

When $ initiates the jQuery.prototype.init initiates and returns an array of elements. But i could not understand how it adds the jQuery method like .css or .hide ,etc. to this array.

I get the static methods. But could not get how it returns and array of elements with all those methods.

  • 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-10T08:27:23+00:00Added an answer on June 10, 2026 at 8:27 am

    I don’t like that pattern either. They have an init function, which is the constructor of all jQuery instances – the jQuery function itself is just a wrapper around that object creation with new:

    function jQuery(…) { return new init(…); }
    

    Then, they add the methods of those instances to the init.prototype object. This object is exposed as an interface at jQuery.fn. Also, they set the prototype property of the jQuery function to that object – for those who don’t use the fn property. Now you have

    jQuery.prototype = jQuery.fn = […]init.prototype
    

    But they also do two [weird] things:

    • overwriting the constructor property of the prototype object, setting it to the jQuery function
    • exposing the init function on jQuery.fn – its own prototype. This might allow Extending $.fn.init function, but is very confusing

    I think they need/want to do all this to be fool-proof, but their code is a mess – starting with that object literal and assigning the init prototype things afterwards.

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

Sidebar

Related Questions

This question comes to you from someone who's been burned by SVN before and
This question comes from a range of other questions that all deal with essentially
First of all: This question is not directly programming related. However, the problem only
Well, first of all sorry about this question it must be pretty straight forward
first of all this is my third question about web services here and i
First of all, the context of this question is: Cannot install psycopg2 on OSX
First of all I am not a designer. so this question is may be
First of all, I did some searching for an answer to this question...but I
First of all, I am a WEB NOOB. Which probably explains this question. Anyway,
First of all, I'm fairly new to Java, so sorry if this question is

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.