当我把孔夫子的《论语》,翻译成 JavaScript 的形式,看起来似乎很有趣。
// 论语_IT版
document.name = "Confucian Analects";
// 子曰:
Confucius.Say(function(you) {
// 学而时习之, 不亦说乎?
if (Study() && OftenReview()) {
you.SetEmotion("delight");
}
// 有朋自远方来, 不亦乐乎?
if (friends.Come(faraway, you.house)) {
you.SetEmotion("glad");
}
// 人不知而不愠,不亦君子乎?
if (!other.Understand(you) && !you.areMad()) {
you.SetStatus("gentleman");
}
});
// 曾子曰:
Mr_Zeng.Say(function() {
// 吾日三省吾身:
var time = 24 * 3600 * 1e3;
var fun_daily = function() {
// 为人谋而不忠乎?
if (false == this.isFaithful(others)) {
throw new Error("Not faithful!");
}
// 与朋友交而不信乎?
if (false == this.isHonest(friends)) {
throw new Error("Not honest!");
}
// 传不习乎?
if (false == this.HasReview(teaching)) {
throw new Error("Not done!");
}
}
setInterval(fun_daily, time);
});