title: In JavaScript, why pass the context as an argument to a function call when the context is already determined by who calls it?
body: <p>A read an article on Medium called </p>
  
  <blockquote>
    <p>You Must Understand These 14 JavaScript Functions by bitfish</p>
  </blockquote>
  
  <p>In the article the author writes about functions a JavaScript developer must know or understand when/before a Job Interview - for position as a JavaScript developer.</p>
  
  <p>In the examples there is a constant usage of passing in a context as an optional argument. Unfortunately the author does not go into details on why we would pass a context argument like here: </p>
  
  <pre><code>mappedArr[i] = fn.call(context, arr[i], i, this); 
  </code></pre>
  
  <p>My question is "In JavaScript, why pass the context as an argument to a function call when the context is already determined by who calls it?" </p>
  
  <p>Under what condition is it useful to have that context available (another context)?</p>
  
  <p>Here is the code listed below:</p>
  
  <pre><code>let selfMap = function(fn, context) {
  
     let arr = Array.prototype.slice.call(this);
     let mappedArr = Array();
     for(let i=0; i &lt; arr.length; i++) {
  
       if (! arr.hasOwnProperty(i)) continue;
  
       let info = [];
       info.push({ "context" : context } );
       info.push({ "arr[i]" : arr[i] } );
       info.push({ "i" : i } );
       info.push({ "this" : this } );
       console.log(info);
  
       mappedArr[i] = fn.call(context, arr[i], i, this); 
  
     } 
     return mappedArr;
  
   }; 
  </code></pre>
  
  <p>And then call it using:</p>
  
  <pre><code>Array.prototype. selfMap = selfMap;
  [1,2,3].myMap(n =&gt; n * 2);
  </code></pre>
  
  <p>Why would one provide a context as a second argument to myMap? I think there may be a JavaScript Design Pattern for this, but at this time I could not find any references, due to all the debris of search results on Google that are unrelated to my search. </p>
  
  <p>I did write a function and passed in the context as a second argument but I am not sure, though I could come up with my own thoughts, what is the main reason for doing this?</p>
  
  <p>Here is my example of using it:</p>
  
  <pre><code>[1,2,3].selfMap((n, o, p) =&gt; {
  
       let info = [];
       info.push({ "n" : n } );
       info.push({ "o" : o } );
       info.push({ "p" : p } );
       info.push({ "this" : this } );
       console.log(info)
       return n * 2;
  
  });
  </code></pre>
  
  <p>Could pass this or window or {} </p>
  
  <p>Context would be equal to the current context of where we called the method from</p>
  
  <pre><code>[1,2,3].selfMap((n, o, context) =&gt; {
  
           let info = [];
           info.push({ "n" : n } );
           info.push({ "o" : o } );
           info.push({ "context" : context } );
           info.push({ "this" : this } );
           console.log(info)
           return n * 2;
  
  }, this);
  </code></pre>
  
  <p>Window as context argument</p>
  
  <pre><code>[1,2,3].selfMap((n, o, context) =&gt; {
  
       let info = [];
       info.push({ "n" : n } );
       info.push({ "o" : o } );
       info.push({ "context" : context } );
       info.push({ "this" : this } );
       console.log(info)
       return n * 2;
  
  }, window);
  </code></pre>
  
  <p>And we could use a custom object</p>
  
  <pre><code>[1,2,3].selfMap((n, o, context) =&gt; {
  
       let info = [];
       info.push({ "n" : n } );
       info.push({ "o" : o } );
       info.push({ "context" : context } );
       info.push({ "this" : this } );
       console.log(info)
       return n * 2;
  
  }, { something: 1 });
  </code></pre>
  
  <p>So, I know that a context can be passed, but I don't know why I might want to pass in a context. </p>
  
  <p>Please with-in your answer provide not only an explanation but an example(s) to clarify your explanation.</p>
  
  <p><strong>Thank You</strong></p>