Allow extensions to easily override a function and call super

This commit is contained in:
Toby Zerner 2015-05-02 08:46:38 +09:30
parent 6d3e3e5c29
commit e3110454ae

View File

@ -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));
}
}