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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:53:59+00:00 2026-05-21T18:53:59+00:00

Had a question about the ‘duck punching’ pattern I first encountered on Paul Irish’s

  • 0

Had a question about the ‘duck punching’ pattern I first encountered on Paul Irish’s blog. I get the general premise… save a ref to an existing function, then replace the existing function with a conditional branch that will call a new function if condition is met, or the old version if not. My question is why do we have to use the “apply” with ‘this’ as the first param when we call the _old function? I understand how apply works, but I’m looking for some clarification on why it is necessary.

(function($){

        // store original reference to the method
        var _old = $.fn.method;

        $.fn.method = function(arg1,arg2){

            if ( ... condition ... ) {
               return  .... 
            } else {           // do the default
               return _old.apply(this,arguments);
            }
        };
    })(jQuery);
  • 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-21T18:53:59+00:00Added an answer on May 21, 2026 at 6:53 pm

    Consider this example

    var obj = {
        foo: "bar",
        baz: function () {
            return this.foo;
        }
    };
    o = obj.baz;
    obj.baz(); // "bar"
    o(); // undefined
    

    if you call a method with obj.baz, the object that is behind the dot is the function’s context (this will refer to this object).
    if you store a method in a variable, you lose the information about the context. In that case, the context will be set to the global object.

    var obj = {
        baz: function () {
            return this;
        }
    };
    o = obj.baz;
    obj.baz() === obj; // true
    o() === obj; // false
    o() === window; // true
    

    A proper context will likely be important for the .method to work as intended.

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

Sidebar

Related Questions

just had a general question about how to approach a certain problem I'm facing.
I had asked a question about this earlier, but it didn't get answered right
I had a general question about extracting code from a visual studio web test.
I had a question about a program I've been trying to get running. Encrypt
I just had a general question about Ruby on Rails and the attr_accessible attributes
I had two question about Erlang. Is design pattern of concept to be suitable
I always had a question about heap memory behaviour. Profiling my app i get
I had a question about indices on a table and I put it up
I had a question about Java Class Path variables. If I have multiple jars
I just had a question about aligning two expand-collapse boxes and got an answer

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.