Skip to content

Latest commit

 

History

History
17 lines (11 loc) · 619 Bytes

README.md

File metadata and controls

17 lines (11 loc) · 619 Bytes

Fake operator overloading for JavaScript

The type Point uses fake operator overloading and lets you do the following:

var Point = require("./point.js").Point;
var p = new Point();

p._ = new Point(1, 2) + new Point(3, 4) + new Point(5, 6);
console.log(p.toString()); // Point(9, 12)

Caveats:

  • The overloaded operators only work when used together with an assignment, in the above manner.
  • "" + mypoint won't invoke toString(), but valueOf(). Work-around: "" + mypoint._