Fake operator overloading used by a type Point
JavaScript
Switch branches/tags
Nothing to show
Pull request Compare This branch is even with rauschma:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md
point.js
point.spec.js

README.md

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._