Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

DynamicProtoDelegate

DynamicProtoDelegate<DPType>: (theTarget: DPType, baseFuncProxy?: DPType) => void

The delegate signature for the function used as the callback for dynamicProto()

param

This is the real "this" of the current target object

param

The is a proxy object which ONLY contains this function that existed on the "this" instance before calling dynamicProto, it does NOT contain properties of this. This is basically equivalent to using the "super" keyword.

Type parameters

  • DPType

    This is the generic type of the class, used to keep intellisense valid for the proxy instance, even though it is only a proxy that only contains the functions

Type declaration

    • (theTarget: DPType, baseFuncProxy?: DPType): void
    • Parameters

      • theTarget: DPType
      • Optional baseFuncProxy: DPType

      Returns void

Functions

_hasVisited

  • _hasVisited(values: any[], value: any): boolean
  • Returns whether the value is included in the array

    Parameters

    • values: any[]

      The array of values

    • value: any

      The value

    Returns boolean

dynamicProto

  • dynamicProto<DPType, DPCls>(theClass: DPCls, target: DPType, delegateFunc: DynamicProtoDelegate<DPType>): void
  • Helper function when creating dynamic (inline) functions for classes, this helper performs the following tasks :-

    • Saves references to all defined base class functions
    • Calls the delegateFunc with the current target (this) and a base object reference that can be used to call all "super" functions.
    • Will populate the class prototype for all overridden functions to support class extension that call the prototype instance. Callers should use this helper when declaring all function within the constructor of a class, as mentioned above the delegateFunc is passed both the target "this" and an object that can be used to call any base (super) functions, using this based object in place of super.XXX() (which gets expanded to _super.prototype.XXX()) provides a better minification outcome and also ensures the correct "this" context is maintained as TypeScript creates incorrect references using super.XXXX() for dynamically defined functions i.e. Functions defined in the constructor or some other function (rather than declared as complete typescript functions).

      Usage

      import dynamicProto from "@microsoft/dynamicproto-js";
      class ExampleClass extends BaseClass {
        constructor() {
            dynamicProto(ExampleClass, this, (_self, base) => {
                // This will define a function that will be converted to a prototype function
                _self.newFunc = () => {
                    // Access any "this" instance property
                    if (_self.someProperty) {
                        ...
                    }
                }
                // This will define a function that will be converted to a prototype function
                _self.myFunction = () => {
                    // Access any "this" instance property
                    if (_self.someProperty) {
                        // Call the base version of the function that we are overriding
                        base.myFunction();
                    }
                    ...
                }
                _self.initialize = () => {
                    ...
                }
                // Warnings: While the following will work as _self is simply a reference to
                // this, if anyone overrides myFunction() the overridden will be called first
                // as the normal JavaScript method resolution will occur and the defined
                // _self.initialize() function is actually gets removed from the instance and
                // a proxy prototype version is created to reference the created method.
                _self.initialize();
            });
        }
      }

    Type parameters

    • DPType

      This is the generic type of the class, used to keep intellisense valid

    • DPCls

      The type that contains the prototype of the current class

    Parameters

    • theClass: DPCls

      This is the current class instance which contains the prototype for the current class

    • target: DPType

      The current "this" (target) reference, when the class has been extended this.prototype will not be the 'theClass' value.

    • delegateFunc: DynamicProtoDelegate<DPType>

      The callback function (closure) that will create the dynamic function

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc