Flarum (v1.8.10)
    Preparing search index...
    • 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.

      Type Parameters

      • T extends Record<any, any>
      • K extends string | number | symbol

      Parameters

      • object: T

        The object that owns the method

      • methods: K | K[]

        The name or names of the method(s) to override

      • newMethod: (this: T, orig: T[K], ...args: Parameters<T[K]>) => void

        The method to replace it with

      Returns void

      override(Discussion.prototype, 'badges', function(original) {
      const badges = original();
      // do something with badges
      return badges;
      });
      extend(Discussion.prototype, ['oncreate', 'onupdate'], function(original, vnode) {
      // something that needs to be run on creation and update
      });