/[Frey]/trunk/static/lib/Joose/Method.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/static/lib/Joose/Method.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (show annotations)
Wed Jul 2 10:28:49 2008 UTC (15 years, 9 months ago) by dpavlin
File MIME type: application/javascript
File size: 2509 byte(s)
added upstream Joose r4755

http://code2.0beta.co.uk/moose/svn/Joose/trunk/lib
1 /*
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 })

  ViewVC Help
Powered by ViewVC 1.1.26