function foo() { this.tag = 'bar' this.bar = function(txt) { console.log('hello ' + txt); } } var bar = new foo(); function middleware(foo) { oldbar = foo.bar; /* save old function, don't make a reference! */ foo.bar = function(txt) { /* ah, here's our chance to mutate txt argument! */ txt = 'dozed off ' + txt; oldbar(txt); } foo.newtag = 'muhahaha'; } middleware(bar); /* mutate! */ bar.bar('kyle'); console.log(bar.newtag);