title: Having trouble extending a Javascript function with more functions
body: <p>I'm trying to override a Javascript function that is included in a .js file that I cannot modify(it is served from a server our applications aren't deployed on). The function contains functions and variables within it. There is one sub-function that I need to change the behavior of but it is called by another, I can't call it directly. Here it is:</p>
  
  <p>Simplistic version of included file that I can't change:</p>
  
  <pre><code>com.company.topLevelFunc = function () {
    var a = null;
    var b = null;
    var doSomething = function() {
      a = foo;
      b = bar;
    };
    var get = function(cfg) {
      //do stuff
    };
    return {
      //other vars and functions here
      getValue : function (cfg) {
        cfg.url=a + b;
        get(cfg);
      }
    };
  }();
  </code></pre>
  
  <p>The function I need to override is the get(cfg). However, I can't call it directly, I need to go through the getValue(cfg) method and preserve all the other stuff that goes on in the top level function. So I've been trying to override both as follows:</p>
  
  <p>My JS that I full control over, and doesn't work, it errors on the apply saying that 'missing : after property id". Am I doing this correct, not sure how to get the apply to work correctly?</p>
  
  <pre><code>var topLevel = com.company.topLevelFunc;
  myTopLevel = function() {
    var myGet = function(cfg) {
      //do simliar but different stuff from the original get function
    };
    return {
      topLevel.apply(this, arguments);
      getMyValue : function (cfg) {
        cfg.c= a + b +"some other string";
        //do something
        myGet(cfg);
      }
    };
  }();
  </code></pre>