Mercurial > pub > ImplabJs
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 4:fcc63f34d0a2 | 5:3d124d0b9078 |
|---|---|
| 1 "use strict"; | 1 "use strict"; |
| 2 define([], function () { | 2 define([], function () { |
| 3 var slice = Array.prototype.slice; | 3 var slice = Array.prototype.slice; |
| 4 return function (method) { | 4 var override = function (method) { |
| 5 var proxy; | 5 var proxy; |
| 6 | 6 |
| 7 /** @this target object */ | 7 /** @this target object */ |
| 8 proxy = function () { | 8 proxy = function () { |
| 9 var me = this; | 9 var me = this; |
| 10 var inherited = (this.getInherited && this.getInherited(proxy.nom, { | 10 var inherited = (this.getInherited && this.getInherited(proxy.nom, { |
| 11 callee: proxy | 11 callee: proxy |
| 12 })) || function () {}; | 12 })) || function () {}; |
| 13 | |
| 14 inherited.arguments = arguments; | |
| 13 | 15 |
| 14 method.apply(me, [function () { | 16 return method.apply(me, [function () { |
| 15 return inherited.apply(me, arguments); | 17 return inherited.apply(me, arguments); |
| 16 }].concat(slice.apply(arguments))); | 18 }].concat(slice.apply(arguments))); |
| 17 }; | 19 }; |
| 18 | 20 |
| 19 proxy.method = method; | 21 proxy.method = method; |
| 20 proxy.overrides = true; | 22 proxy.overrides = true; |
| 21 | 23 |
| 22 return proxy; | 24 return proxy; |
| 23 }; | 25 }; |
| 26 | |
| 27 override.before = function (method) { | |
| 28 var proxy; | |
| 29 | |
| 30 /** @this target object */ | |
| 31 proxy = function () { | |
| 32 var me = this; | |
| 33 var inherited = (this.getInherited && this.getInherited(proxy.nom, { | |
| 34 callee: proxy | |
| 35 })) || function () {}; | |
| 36 | |
| 37 | |
| 38 method.apply(me, arguments); | |
| 39 return inherited.apply(me, arguments); | |
| 40 }; | |
| 41 | |
| 42 proxy.method = method; | |
| 43 proxy.overrides = true; | |
| 44 | |
| 45 return proxy; | |
| 46 }; | |
| 47 | |
| 48 override.after = function (method) { | |
| 49 var proxy; | |
| 50 | |
| 51 /** @this target object */ | |
| 52 proxy = function () { | |
| 53 var me = this; | |
| 54 var inherited = (this.getInherited && this.getInherited(proxy.nom, { | |
| 55 callee: proxy | |
| 56 })) || function () {}; | |
| 57 | |
| 58 inherited.apply(me, arguments); | |
| 59 | |
| 60 return method.apply(me, arguments); | |
| 61 }; | |
| 62 | |
| 63 proxy.method = method; | |
| 64 proxy.overrides = true; | |
| 65 | |
| 66 return proxy; | |
| 67 }; | |
| 68 | |
| 69 override.hide = function (method) { | |
| 70 method.overrides = false; | |
| 71 return method; | |
| 72 }; | |
| 73 | |
| 74 return override; | |
| 24 }); | 75 }); |
