Email:longsu2010 at yeah dot net
A question always pops up in my mind: "Can I write JavaScript without if blocks?"
Inspired by Chris Owen's explanation of SmallTalk, I wrote An if-less implementation of class SmallTalk.
Boolean.prototype.ifTrue = function (f) {
this && f();
return this;
};
Boolean.prototype.ifFalse = function (f) {
this || f();
return this;
};
// so you can write
(4 < 5).ifTrue(function () {
alert("It is true.");
}).ifFalse(function () {
alert("It isn't true.");
});This example has no practical use, but it is an interesting example from a learning perspective.