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.
Example
Example usage of overriding one method.
override(Discussion.prototype, 'badges', function(original) { constbadges = original(); // do something with badges returnbadges; });
Example
Example usage of overriding multiple methods.
extend(Discussion.prototype, ['oncreate', 'onupdate'], function(original, vnode) { // something that needs to be run on creation and update });
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.
Example
Example usage of overriding one method.
Example
Example usage of overriding multiple methods.