blob: e572d10459c61d09876fa80d6600449ba42a8dbf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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);
|