摘要:
/* 函数的定义 */function a() { return 1; }var b = function () { return 1; };var c = function d() { return 1; }; // d === undefinedvar e = new Function("return 1;");alert(typeof a); //functionalert(typeof b); //functionalert(typeof c); //functionalert(typeof d); //undefinedalert(typeof e); //fun 阅读全文
摘要:
/* 给一个实例化后的空对象添加属性、方法 */obj = {};obj.Name = "张三";obj.Age = 33;obj.ShowInfo = function () { alert(obj.Name + ", " + obj.Age); }obj.ShowInfo(); //张三, 33/* 用函数建立并返回对象 */function GetObj(name, age) { return { Name: name, Age: age, ShowInfo: function () { alert(this.Name + ", &quo 阅读全文
摘要:
var func = function (callback, a, b, c) { return callback(a, b, c);}var funAdd = function (a, b, c) { function callback(a, b, c) { return a + b + c; } return func(callback, a, b, c);}var funMul = function (a, b, c) { function callback(a, b, c) { return a * b * c; } return func(callbac... 阅读全文
摘要:
num = 123;str = "123";alert(num == 123); //truealert(str == 123); //truealert(num === 123); //true; 值相同且类型相同alert(str === 123); //falsealert(typeof num === "number"); //truealert(typeof str === "string"); //true//数组的类型也是 objectalert(typeof []); //objectalert(typeof {}); 阅读全文
摘要:
/* 默认参数 */function func(a, b, c) { a = a === undefined ? 3 : a; //默认 3 b = b === undefined ? 3 : b; //默认 3 c = c === undefined ? 3 : c; //默认 3 return a + b + c;}alert(func(6, 6, 6)); //18alert(func()); //9alert(func(4)); //10alert(func(4, 0)); //7/* 通过闭包预置参数 */function fu... 阅读全文
摘要:
在看几个 js 源码; 感觉不如 Delphi 的代码清晰, js 太灵活性, 需慢慢适应./* 定义一组常量(变量) */var MX1 = function () { };MX1.Max = 100;MX1.Min = 0;MX1.Ave = 50;alert(MX1.Max + ", " + MX1.Min + ", " + MX1.Ave); //100, 0, 50alert(++MX1.Max); //101/* 定义一组函数 */var MX2 = function () { };MX2.Add = function (a, b) { re 阅读全文