79349185

Date: 2025-01-12 01:21:54
Score: 1
Natty:
Report link

Self plug: I wrote a library to do this because TC39 recently abandoned the proposal to introduce it: https://www.npmjs.com/package/@nano-utils/op

User-side looks like:

import { op } from '@nano-utils/op';

class Vector {
    constructor(...elems) {
        this.arr = elems;
    }

    'operator+'(other) {
        return new Vector(...this.arr.map((e, i) => e + other.arr[i]));
    }
}

const a = new Vector(1, 2),
    b = new Vector(3, 4);

console.log(op`${a} + ${b}`); // -> Vector(4, 6)
Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Jason Xu