Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

constructor and record/tuple #115

Closed
Closed
@pabloalmunia

Description

@pabloalmunia

Maybe it may seem strange, but any constructor can return a literal object. Sometimes this is interesting in some special classes:

class Point {
  constructor(x, y) {
    return {x, y};
  }
}
const p = new Point(10, 20);

Of course, we cannot return other than a object: https://tc39.es/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget

As a result, with the current specification of record and tuples we cannot return this kind of elements into a constructor.

class Point {
  constructor(x, y) {
    return #{x, y};
  }
}
const p = new Point(10, 20); // wrong, p is {}

Is it true? Am I right? The idea of immutable object as result of constructor is very atractive for me, but I undestant the special caracteristic of this kind of elements.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions