Options
All
  • Public
  • Public/Protected
  • All
Menu

An interface for comparable objects of the same type. They are compared via a special method 'compareTo'.

typeparam

Type of the items that are compared.

Type parameters

  • T

    Type of the objects to compare.

    class Vector implements Comparable<Vector> {
      constructor(private x: number, private y: number) {}
      add(vector: Vector) : Vector {
        return new Vector(this.x + vector.x, this.y + vectory.y)
      }
      get abs2() : number {
        return this.x*this.x + this.y*this.y;
      }
      get abs() : number {
        return Math.sqrt(this.x*this.x + this.y*this.y);
      }
      compareTo(vector: Vector) : number {
        return this.abs2 - vector.abs2;
      }
      static get compare() : Comparator<Vector> {
        return byProp("abs2")
      }
    }
    
    [new Vector(2,3), new Vector(1,2)].sort(Vector.compare);

Hierarchy

  • Comparable

Index

Methods

Methods

compareTo

  • compareTo(rhs: T): number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • 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