在看几个 js 源码; 感觉不如 Delphi 的代码清晰, js 太灵活性, 需慢慢适应.

/* 定义一组常量(变量) */
var MX1 = function () { };
MX1.Max = 100;
MX1.Min = 0;
MX1.Ave = 50;

alert(MX1.Max + ", " + MX1.Min + ", " + MX1.Ave); //100, 0, 50
alert(++MX1.Max); //101

/* 定义一组函数 */
var MX2 = function () { };
MX2.Add = function (a, b) { return a + b; }
MX2.Dec = function (a, b) { return a - b; }
MX2.Mul = function (a, b) { return a * b; }
MX2.Div = function (a, b) { return a / b; }

var x = 6,
    y = 3;
alert(MX2.Add(x, y)); //9
alert(MX2.Dec(x, y)); //3
alert(MX2.Mul(x, y)); //18
alert(MX2.Div(x, y)); //2

posted on 2012-03-15 10:45  万一  阅读(2504)  评论(1编辑  收藏  举报