Extend an object's method by running its output through a mutating callback
every time it is called.
The callback accepts the method's return value and should perform any
mutations directly on this value. For this reason, this function will not be
effective on methods which return scalar values (numbers, strings, booleans).
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 extending one method.
extend(Discussion.prototype, 'badges', function(badges) {
// do something with `badges`
});
Example
Example usage of extending multiple methods.
extend(IndexPage.prototype, ['oncreate', 'onupdate'], function(vnode) { // something that needs to be run on creation and update });
Extend an object's method by running its output through a mutating callback every time it is called.
The callback accepts the method's return value and should perform any mutations directly on this value. For this reason, this function will not be effective on methods which return scalar values (numbers, strings, booleans).
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
Example usage of extending multiple methods.