1

I was reading about how classes work and came across this:

This es6 syntax

class Point {
    x: number;
    y: number;
    constructor(x: number, y: number) {
        this.x = x;
        this.y = y;
    }
    add(point: Point) {
        return new Point(this.x + point.x, this.y + point.y);
    }
}

gives an es5 emit as:

"use strict";

var Point =
/*#__PURE__*/
function () {
  function Point(x, y) {
    this.x = x;
    this.y = y;
  }

  var _proto = Point.prototype;

  _proto.add = function add(point) {
    return new Point(this.x + point.x, this.y + point.y);
  };

  return Point;
}();

I'm not able to understand why the need for the trailing parentheses.

Eru
  • 71
  • 1
  • 6
  • 1
    It's to call the function without needing to name it. It's the same as `var temp = function(){}; temp()` – slebetman Dec 26 '19 at 09:41

0 Answers0