annotate src/implab/declare/override.js @ 5:3d124d0b9078

improved declare/override, added override.before, override.after, override.hide, inherited.arguments.
author cin
date Fri, 16 Jun 2017 02:14:25 +0300
parents fc2517695ee1
children 9663631cbdb9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
1 "use strict";
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
2 define([], function () {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
3 var slice = Array.prototype.slice;
5
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
4 var override = function (method) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
5 var proxy;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
6
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
7 /** @this target object */
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
8 proxy = function () {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
9 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
10 var inherited = (this.getInherited && this.getInherited(proxy.nom, {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
11 callee: proxy
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
12 })) || function () {};
5
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
13
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
14 inherited.arguments = arguments;
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
15
5
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
16 return method.apply(me, [function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
17 return inherited.apply(me, arguments);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
18 }].concat(slice.apply(arguments)));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
19 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
20
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
21 proxy.method = method;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
22 proxy.overrides = true;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
23
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
24 return proxy;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
25 };
5
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
26
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
27 override.before = function (method) {
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
28 var proxy;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
29
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
30 /** @this target object */
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
31 proxy = function () {
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
32 var me = this;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
33 var inherited = (this.getInherited && this.getInherited(proxy.nom, {
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
34 callee: proxy
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
35 })) || function () {};
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
36
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
37
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
38 method.apply(me, arguments);
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
39 return inherited.apply(me, arguments);
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
40 };
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
41
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
42 proxy.method = method;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
43 proxy.overrides = true;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
44
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
45 return proxy;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
46 };
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
47
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
48 override.after = function (method) {
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
49 var proxy;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
50
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
51 /** @this target object */
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
52 proxy = function () {
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
53 var me = this;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
54 var inherited = (this.getInherited && this.getInherited(proxy.nom, {
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
55 callee: proxy
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
56 })) || function () {};
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
57
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
58 inherited.apply(me, arguments);
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
59
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
60 return method.apply(me, arguments);
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
61 };
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
62
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
63 proxy.method = method;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
64 proxy.overrides = true;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
65
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
66 return proxy;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
67 };
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
68
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
69 override.hide = function (method) {
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
70 method.overrides = false;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
71 return method;
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
72 };
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
73
3d124d0b9078 improved declare/override, added override.before, override.after, override.hide,
cin
parents: 0
diff changeset
74 return override;
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
75 });