Flarum (v2.0.0-beta.6)
    Preparing search index...
    • 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.

      Type Parameters

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

      Parameters

      • object: string | T

        The object that owns the method

      • methods: K | K[]

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

      • callback: (this: T, val: ReturnType<T[K]>, ...args: Parameters<T[K]>) => void

        A callback which mutates the method's output

      Returns void

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