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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:44:32+00:00 2026-06-17T06:44:32+00:00

I am making some test with extend and I got a little puzzled after

  • 0

I am making some test with extend and I got a little puzzled after some observations I made. First observations:

console.log($.extend === $.fn.extend); // trure
// and since $ === jQuery then ...
console.log(jQuery.extend === jQuery.fn.extend); // true

So far so good, isn’t it? Given the above results I then thought that doing this:

// SNIPPET 1
$.extend({
   log: function(m) {
      console.log(m);
   }
});

and this:

// SNIPPET 2
$.fn.extend({
   log: function(m) {
      console.log(m);
   }
});

was the same very thing. But in fact things stand in a very different way. In fact if you run SNIPPET 1 and then do:

$("body").log("whatever");

you get an error (log is not defined). But you can do:

$.log("whatever");

If you run instead SNIPPET 2 you get the opposite result, that is to say:

$("body").log("whatever"); // this will work
$.log("whatever"); // this won't

What the heck? I appreciate the fact that .extend extends the object against which it is executed ($ vs $.prototype) but what I do not get is how iit does it! Expecially given the fact that:

$.extend === $.fn.extend // true

The function is the same!! How can it produce 2 different results?

  • 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-17T06:44:33+00:00Added an answer on June 17, 2026 at 6:44 am

    Inside the function this will be different. In the first case it will be $, in the second $.fn.

    Have a look at the source code:

    jQuery.extend = jQuery.fn.extend = function() {
        var options, name, src, copy, copyIsArray, clone,
            target = arguments[0] || {},
            i = 1,
            length = arguments.length,
            deep = false;
    
        // ...
    
        // extend jQuery itself if only one argument is passed
        if ( length === i ) {
            target = this;
             --i;
        }
    
        // ...
    };
    

    Learn more about this.

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

Sidebar

Related Questions

I'm starting with Ruby, and while making some test samples, I've stumbled against an
I'm making some game, and I have made it pretty much all, but not
I was making some test with my JSF-app and when I tried it in
I'm making some load test using Siege and Apache benchmarking tool . I count
A while ago I was making some test in JavaScript, and played with a
I have some test classes that are making use of spring-batch, and hibernate. My
I've had a problem where making the font weight of some text Bold made
have my appid and secret key from facebook and i just making some test
In attempting to work with a test page for making some jquery getJSON calls
I am testing a Magento 1.6.2 installation, by making some test orders. When 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.