Substituir a comparação de equivalência em JavaScript

É possível substituir a comparação de equivalência em JavaScript?

O mais próximo que cheguei de uma solução é definir a função valueOf e chamar valueOf com um sinal de adição na frente do objeto.

Isso funciona.

<code>equal(+x == +y, true);
</code>

Mas isso falha.

<code>equal(x == y, true, "why does this fail.");
</code>

Aqui estão meus casos de teste.

<code>var Obj = function (val) {
    this.value = val;
};
Obj.prototype.toString = function () {
    return this.value;
};
Obj.prototype.valueOf = function () {
    return this.value;
};
var x = new Obj(42);
var y = new Obj(42);
var z = new Obj(10);
test("Comparing custom objects", function () {
    equal(x >= y, true);
    equal(x <= y, true);
    equal(x >= z, true);
    equal(y >= z, true);
    equal(x.toString(), y.toString());
    equal(+x == +y, true);
    equal(x == y, true, "why does this fails.");
});
</code>

Demonstração aqui:http://jsfiddle.net/tWyHg/5/

questionAnswers(4)

yourAnswerToTheQuestion