mozilla
Your Search Results

    super

    This is an experimental technology, part of the ECMAScript 6 (Harmony) proposal.
    Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.

    The super keyword is used to call functions on an object's parent.

    The super.prop and super[expr] expressions are valid in any method definition in both classes and object literals.

    Syntax

    super([arguments]); // calls the parent constructor.
    super.functionOnParent([arguments]);
    

    Description

    When used in a constructor, the super keyword appears alone and must be used before the this keyword can be used. This keyword can also be used to call to call functions on a parent object.

    Example

    This code snippet is taken from the classes sample (live demo).

    class Square extends Polygon {
      constructor(length) {
        // Here, it calls the parent class' constructor with lengths
        // provided for the Polygon's width and height
        super(length, length);
        // Note: In derived classes, super() must be called before you
        // can use 'this'. Leaving this out will cause a reference error.
        this.name = 'Square';
      }
    
      get area() {
        return this.height * this.width;
      }
    
      set area(value) {
        this.area = value;
      } 
    }

    Specifications

    Specification Status Comment
    ECMAScript 6 (ECMA-262)
    The definition of 'super' in that specification.
    Release Candidate Initial definition.

    Browser compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support 42.0 Not supported
    bug 1066239
    ? ? ?
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile
    Basic support ? 42.0 Not supported
    bug 1066239
    ? ? ?

    See also

    Document Tags and Contributors

    Contributors to this page: kmaglione, jpmedley, fscholz
    Last updated by: kmaglione,
    Hide Sidebar