Skip to content

Instantly share code, notes, and snippets.

@littledan
Last active January 4, 2018 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save littledan/19c09a09d2afe7558cdfd6fdae18f956 to your computer and use it in GitHub Desktop.
Save littledan/19c09a09d2afe7558cdfd6fdae18f956 to your computer and use it in GitHub Desktop.
class Vec {
#x;
#y;
#z;
constructor(x, y, z) {
this.#x = x;
this.#y = y;
this.#z = z;
}
static #operators = {
"+"(a, b) { return new Vec(a.#x + b.#x, a.#y + b.#y, a.#z + b.#z); }
"-"(a, b) { return new Vec(a.#x - b.#x, a.#y - b.#y, a.#z - b.#z); }
};
get [Symbol.operators]() { return Vec.#operators }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment