Dev HelpersOpen library
← Back

Build an instance with a static factory

Build an instance with a static factory in JavaScript.

Open this example in the interactive library

Source code

class Point {
  constructor(x, y) {
    Object.assign(this, { x, y });
  }
  static origin() {
    return new Point(0, 0);
  }
}
console.log(Point.origin());

Sample output

Point { x: 0, y: 0 }