mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 15:43:59 +08:00
Allow extensions to easily override a function and call super
This commit is contained in:
parent
6d3e3e5c29
commit
e3110454ae
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user