The object that owns the method
The name or names of the method(s) to override
The method to replace it with
Rest
...args: Parameters<T[K]>Example usage of overriding one method.
override(Discussion.prototype, 'badges', function(original) {
const badges = original();
// do something with badges
return badges;
});
Example usage of overriding multiple methods.
extend(Discussion.prototype, ['oncreate', 'onupdate'], function(original, vnode) {
// something that needs to be run on creation and update
});
Generated using TypeDoc v0.24.8
Override an object's method by replacing it with a new function, so that the new function will be run every time the object's method is called.
The replacement function accepts the original method as its first argument, which is like a call to
super
. Any arguments passed to the original method are also passed to the replacement.Care should be taken to extend the correct object – in most cases, a class' prototype will be the desired target of extension, not the class itself.