Correct way(s) to call/trigger an anonymous function in JavaScript?
<p>Let's say I have this function, which is like a different version of and utilizes <code>Array.push</code> with some different logic inside it:</p>

<pre><code>var array_values = [];

function pump_array(needle, haystack, callback) {
    var pushed = false;

    if(haystack.indexOf(needle) === -1) {
        haystack.push(needle);
        pushed = true;
    }

    if(typeof callback == 'function') {
        callback(haystack, pushed);
    }
}
</code></pre>

<p>And now if I we use it in this manner:</p>

<pre><code>var pump_array_callback = function(new_data_in_array_values, pushed) {
    if(pushed) {
        console.log('added "first" into "array_values[]"');
    } else {
        console.log('"first" already in "array_values[]"');
    }

    console.log(new_data_in_array_values);
};

pump_array('first', array_values, pump_array_callback);
pump_array('first', array_values, pump_array_callback);
</code></pre>

<p>The first function call of <code>pump_array</code> will output:</p>

<blockquote>
  <p><code>added "first" into "array_values[]"</code></p>
</blockquote>

<p>And second will do the opposite:</p>

<blockquote>
  <p><code>"first" already in "array_values[]"</code></p>
</blockquote>

<p>So basically, my question is:</p>

<p>Is this the right way to call/execute an anonymous function in a function, or elsewhere:</p>

<pre><code>if(typeof callback == 'function') {
    callback(haystack, pushed);
}
</code></pre>

<p>And are there any other methods of doing the same, in a more pragmatic way?</p>