Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/inherit/docs/types/index.d"

Index

Functions

Functions

Export assignment inherit

  • inherit(ctor: any, superCtor: any): any
  • Implements prototypical inheritance by replacing the prototype of one constructor with the prototype of another constructor.

    throws

    first argument must be either an object or a function which can inherit

    throws

    second argument must be either an object or a function from which a constructor can inherit

    throws

    second argument must have an inheritable prototype

    Parameters

    • ctor: any

      constructor which will inherit

    • superCtor: any

      super (parent) constructor

    Returns any

    child constructor

    Example

    function Foo() {
        return this;
    }
    Foo.prototype.beep = function beep() {
        return 'boop';
    };
    
    function Bar() {
        Foo.call( this );
        return this;
    }
    inherit( Bar, Foo );
    
    var bar = new Bar();
    var v = bar.beep();
    // returns 'boop'