1 |
dpavlin |
46 |
/* |
2 |
|
|
* A class for methods |
3 |
|
|
* Originally defined in Joose.js |
4 |
|
|
*/ |
5 |
|
|
|
6 |
|
|
Class("Joose.Method", { |
7 |
|
|
methods: { |
8 |
|
|
|
9 |
|
|
// creates a new method object with the same name |
10 |
|
|
_makeWrapped: function (func) { |
11 |
|
|
return this.meta.instantiate(this.getName(), func); // Should there be , this.getProps() ??? |
12 |
|
|
}, |
13 |
|
|
|
14 |
|
|
around: function (func) { |
15 |
|
|
var orig = this.getBody(); |
16 |
|
|
return this._makeWrapped(function () { |
17 |
|
|
var me = this; |
18 |
|
|
var bound = function () { return orig.apply(me, arguments) } |
19 |
|
|
return func.apply(this, Joose.A.concat([bound], arguments)) |
20 |
|
|
}) |
21 |
|
|
}, |
22 |
|
|
before: function (func) { |
23 |
|
|
var orig = this.getBody(); |
24 |
|
|
return this._makeWrapped(function () { |
25 |
|
|
func.apply(this, arguments) |
26 |
|
|
return orig.apply(this, arguments); |
27 |
|
|
}) |
28 |
|
|
}, |
29 |
|
|
after: function (func) { |
30 |
|
|
var orig = this.getBody(); |
31 |
|
|
return this._makeWrapped(function () { |
32 |
|
|
var ret = orig.apply(this, arguments); |
33 |
|
|
func.apply(this, arguments); |
34 |
|
|
return ret |
35 |
|
|
}) |
36 |
|
|
}, |
37 |
|
|
|
38 |
|
|
override: function (func) { |
39 |
|
|
var orig = this.getBody(); |
40 |
|
|
return this._makeWrapped(function () { |
41 |
|
|
var me = this; |
42 |
|
|
var bound = function () { return orig.apply(me, arguments) } |
43 |
|
|
var before = this.SUPER; |
44 |
|
|
this.SUPER = bound; |
45 |
|
|
var ret = func.apply(this, arguments); |
46 |
|
|
this.SUPER = before; |
47 |
|
|
return ret |
48 |
|
|
}) |
49 |
|
|
}, |
50 |
|
|
|
51 |
|
|
augment: function (func) { |
52 |
|
|
var orig = this.getBody(); |
53 |
|
|
orig.source = orig.toString(); |
54 |
|
|
return this._makeWrapped(function () { |
55 |
|
|
var exe = orig; |
56 |
|
|
var me = this; |
57 |
|
|
var inner = func |
58 |
|
|
inner.source = inner.toString(); |
59 |
|
|
if(!this.__INNER_STACK__) { |
60 |
|
|
this.__INNER_STACK__ = []; |
61 |
|
|
}; |
62 |
|
|
this.__INNER_STACK__.push(inner) |
63 |
|
|
var before = this.INNER; |
64 |
|
|
this.INNER = function () {return me.__INNER_STACK__.pop().apply(me, arguments) }; |
65 |
|
|
var ret = orig.apply(this, arguments); |
66 |
|
|
this.INNER = before; |
67 |
|
|
return ret |
68 |
|
|
}) |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
}) |