# HG changeset patch # User cin # Date 1497568465 -10800 # Node ID 3d124d0b9078837e9c91456bcf3aa742b6e679f1 # Parent fcc63f34d0a2acdb0cf4df91b9bb21e0c08874b5 improved declare/override, added override.before, override.after, override.hide, inherited.arguments. diff -r fcc63f34d0a2 -r 3d124d0b9078 src/implab/declare/override.js --- a/src/implab/declare/override.js Thu Jun 08 15:15:24 2017 +0300 +++ b/src/implab/declare/override.js Fri Jun 16 02:14:25 2017 +0300 @@ -1,7 +1,7 @@ "use strict"; define([], function () { var slice = Array.prototype.slice; - return function (method) { + var override = function (method) { var proxy; /** @this target object */ @@ -10,8 +10,10 @@ var inherited = (this.getInherited && this.getInherited(proxy.nom, { callee: proxy })) || function () {}; + + inherited.arguments = arguments; - method.apply(me, [function () { + return method.apply(me, [function () { return inherited.apply(me, arguments); }].concat(slice.apply(arguments))); }; @@ -21,4 +23,53 @@ return proxy; }; + + override.before = function (method) { + var proxy; + + /** @this target object */ + proxy = function () { + var me = this; + var inherited = (this.getInherited && this.getInherited(proxy.nom, { + callee: proxy + })) || function () {}; + + + method.apply(me, arguments); + return inherited.apply(me, arguments); + }; + + proxy.method = method; + proxy.overrides = true; + + return proxy; + }; + + override.after = function (method) { + var proxy; + + /** @this target object */ + proxy = function () { + var me = this; + var inherited = (this.getInherited && this.getInherited(proxy.nom, { + callee: proxy + })) || function () {}; + + inherited.apply(me, arguments); + + return method.apply(me, arguments); + }; + + proxy.method = method; + proxy.overrides = true; + + return proxy; + }; + + override.hide = function (method) { + method.overrides = false; + return method; + }; + + return override; }); \ No newline at end of file