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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:22:15+00:00 2026-05-13T07:22:15+00:00

What is apply invocation pattern in Javascript in reference to function invocation patterns and

  • 0

What is apply invocation pattern in Javascript in reference to function invocation patterns and how can I use it?
What are the benefits of using this invocation pattern.

  • 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-13T07:22:15+00:00Added an answer on May 13, 2026 at 7:22 am

    The use of apply is related to the function context (the this keyword) and argument passing.

    First, I think you should know in which cases the this keyword is implicitly set:

    1- When a function is called as a method (the function is invoked as member of an object):

    obj.method(); // 'this' inside method will refer to obj
    

    2- A normal function call:

    myFunction(); // 'this' inside the function will refer to the Global object
    // or 
    (function () {})();
    

    3- When the new operator is used:

    var obj = new MyObj(); // this will refer to a newly created object.
    

    Here is when apply and call come, those methods let you set explicitly the context when you invoke a function, eg.:

    function test(a) {
      alert(this + a);
    }
    
    test.call('Hello', ' world!');
    

    In the above code, when the test function is called setting the this keyword to a String ('Hello'), and passing the a argument (' world.').

    Both, call and apply change the context of the executing function (the this keyword) inside the called function, but the difference between them is that with apply, you can send an Array or an Array-like object as the arguments of the function to be executed, which is extremely useful, for example:

    function sum() {
      var result = 0;
      for (var i = 0; i < arguments.length; i++) {
        result += arguments[i];
      }
      return result;
    }
    
    var args = [1,2,3];
    sum.apply(null, args); // will return 6
    

    That can avoid some very hacky, bad (and common) eval calls like:

    eval('sum(' + args.join() +')');
    

    Another example, the Math.max and Math.min methods, those methods can receive an arbitrary number of arguments like:

    var max = Math.max(2,4,6,8); // 8
    

    But what if you have an Array of numbers?

    var numbers = [2,4,6,8];
    numbers.push(10);
    var max = Math.max.apply(null, numbers); // 10
    

    Also note that when null or undefined is used as the this argument with call or apply, the this object will refer to the Global object (similar to the case #2, normal function invocation).

    For the Math.max example, the context is not really relevant, since they are just like “static” methods, the this keyword is not used internally…

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

Sidebar

Related Questions

Objective: Apply CSS Filters to video using html5 and JavaScript. Contraints: The solution must
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
i'm trying to apply the MVVM pattern in my application with MVVM Light. I've
I am trying to use the KeyChainitemwrapper provided by apple. My project is using
I visiting this site and I am eager to apply for the Master’s or
I couldn't find a reason for this problem. The function getfruits returns a pointer
The apply documentation mentions that Where 'X' has named dimnames, it can be a
My current program need to use programatically create a XPathExpression instance to apply to
I'm unable to use native code functions as JavaScript objects in WebKit-based browsers. Is
If you run this in the chrome console: console.log.apply(null, [array]) Chrome gives you back

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.