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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:06:56+00:00 2026-06-13T13:06:56+00:00

As an example, copied from jQuery 1.2.6: jQuery.fn = jQuery.prototype = { init: function(

  • 0

As an example, copied from jQuery 1.2.6:

jQuery.fn = jQuery.prototype = {
    init: function( selector, context ) {
        // Make sure that a selection was provided
        selector = selector || document;
        ..........
    },
};

I have read some posts here like JavaScript: What are .extend and .prototype used for? and know a prototype can be used in a subclass to extend some methods.

But I cannot understand the usage in the above snippet from jQuery.

Are there any canonical documents describing the prototype?

Thanks.

  • 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-13T13:06:57+00:00Added an answer on June 13, 2026 at 1:06 pm

    All objects have a prototype property. It is simply an object from which other objects can inherit properties. The snippet you have posted simply assigns an object with some properties (such as init) to the prototype of jQuery, and aliases jQuery.prototype to jQuery.fn because fn is shorter and quicker to type. If you forget about jQuery temporarily, consider this simple example:

    function Person(name) {
        this.name = name;
    }
    Person.prototype.sayHello = function () {
        alert(this.name + " says hello");
    };
    
    var james = new Person("James");
    james.sayHello(); // Alerts "James says hello"
    

    In this example, Person is a constructor function. It can be instantiated by calling it with the new operator. Inside the constructor, the this keyword refers to the instance, so every instance has its own name property.

    The prototype of Person is shared between all instances. So all instances of Person have a sayHello method that they inherit from Person.prototype. By defining the sayHello method as a property of Person.prototype we are saving memory. We could just as easily give every instance of Person its own copy of the method (by assigning it to this.sayHello inside the constructor), but that’s not as efficient.

    In jQuery, when you call the $ method, you’re really creating an instance of jQuery.prototype.init (remember that jQuery.fn === jQuery.prototype):

    return new jQuery.fn.init(selector, context, rootjQuery);
    

    And if you look at jQuery.fn.init:

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

    So really, you’re creating an instance of jQuery which has access to all the methods declared on jQuery.prototype. As discussed previously, this is much more efficient than declaring those methods on each instance of jQuery.

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

Sidebar

Related Questions

I copied this example from api.jquery.com $('.target').change(function() { alert('Handler for .change() called.'); }); I
I copied this code from an example . I've read it 100 times. Array.prototype.map
I made an example , I copied it straight from the jQuery website yet,
I ran an example copied from: http://developers.facebook.com/docs/reference/javascript/ http://developers.facebook.com/docs/reference/javascript/FB.api/ (I only changed my APP_ID) <div
I copied the example straight from their page: http://jsfiddle.net/D2RLR/631/ ... and I get the
I've copied and pasted the example ejb-jar.xml and jboss.xml file from http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch6.chapt.html#ch6.mdbejbjar.ex and I'm
Still fighting with templates. In this example, despite the fact that is copied straight
I have some code I copied from an example and I am not certain
I have two pages - a simple HTML code example page from a jQuery
I am learning to use mahout by starting with a example copied from the

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.