Comparable object

Demonstrates valueOf to make objects somewhat comparable

by doug65536

JavaScript

function Comparable(x) {
    this.x = x;
}
Comparable.prototype = {
    valueOf: function() {
        return this.x;
    }
};

var a = new Comparable(123), b = new Comparable(123);
console.log(a >= b && a <= b);