<p>I have a function, <code>a()</code>, that I want to override, but also have the original <code>a()</code> be performed in an order depending on the context. For example, sometimes when I'm generating a page I'll want to override like this:</p>

<pre><code>function a() {
    new_code();
    original_a();
}
</code></pre>

<p>and sometimes like this:</p>

<pre><code>function a() {
    original_a();
    other_new_code();
}
</code></pre>

<p>How do I get that <code>original_a()</code> from within the over-riding <code>a()</code>? Is it even possible?</p>

<p>Please don't suggest alternatives to over-riding in this way, I know of many. I'm asking about this way specifically.</p>

You could do something like this:
```
```
var a = (function() {
    var original_a = a;

    if (condition) {
        return function() {
            new_code();
            original_a();
        }
    } else {
        return function() {
            original_a();
            other_new_code();
        }
    }
})();
```
```
Declaring
```
original_a
```
inside an anonymous function keeps it from cluttering the global namespace, but it's available in the inner functions.
Like Nerdmaster mentioned in the comments, be sure to include the
```
()
```
at the end. You want to call the outer function and store the
result
(one of the two inner functions) in
```
a
```
, not store the outer function itself in
```
a
```
.