From ea9d49b15ef99c3460a0dc03f49183c9bc2c0aee Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 2 May 2015 08:46:38 +0930 Subject: [PATCH] Allow extensions to easily override a function and call super --- js/lib/extension-utils.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/lib/extension-utils.js b/js/lib/extension-utils.js index c54bcfc06..55712bace 100644 --- a/js/lib/extension-utils.js +++ b/js/lib/extension-utils.js @@ -1,8 +1,16 @@ export function extend(object, func, extension) { var oldFunc = object[func]; object[func] = function() { - var value = oldFunc.apply(this, arguments); var args = [].slice.apply(arguments); + var value = oldFunc.apply(this, args); return extension.apply(this, [value].concat(args)); } }; + +export function override(object, func, override) { + var parent = object[func]; + object[func] = function() { + var args = [].slice.apply(arguments); + return override.apply(this, [parent].concat(args)); + } +}