function setup(method) { window[method] = fake; }; var fake = function() { return "faked"; }; var real = function() { return "real"; }; setup("real"); console.log(real.toString()); console.log(real() == "faked"); /* this works but isn't as pretty */ function setup(method) { return fake; }; ... real = setup(real); console.log(real() == "faked");