摘要: if (..) { ... } else if (..) { ... } else { ... } switch (..) { case A: ... break; case B: ... break; case C: ... break; default: ... break; } while (..) { ... } do ... while (... 阅读全文
posted @ 2009-03-04 21:42 万一 阅读(1630) 评论(0) 推荐(0)
摘要: 函数的名称function fun() { alert(123);}fun(); //123f = function() { alert(123);}f(); //123msg = alert;msg(123); //123函数的返回值function fun() { var num = 1; return num; //函数可以没有 return; 如果有 之后的代码不会被执行 num++; return num;}var r = fun();alert(r); //1函数的既定参数和实际参数/* 预定参数的个数 */function fun(a... 阅读全文
posted @ 2009-03-04 16:58 万一 阅读(1843) 评论(0) 推荐(0)
摘要: 给对象增减方法 function Rect(w, h) { this.width = w; this.height = h; } var r = new Rect(2, 3); /* 给 r 对象增加一个计算面积的方法 area() */ r.area = function() {return this.width * this.height}; alert(r.width); ... 阅读全文
posted @ 2009-03-04 12:21 万一 阅读(1655) 评论(2) 推荐(0)
摘要: prototype(原型) 是 JavaScript 中类的继承手段;一个类也不过是一组属性和方法的集合, 所谓继承就是继承属性或方法;属性是个值, 方法是个函数, JavaScript 喜欢把它们都叫成属性, 我们喜欢把它们叫做成员;JavaScript 默认让每个函数都拥有一个 prototype 对象, 它可以指向一个对象或函数(函数也是对象, 一回事);绕来绕去, 最终是四通八达...类成员与对象成员function Rect(w, h) { Rect.name = "My Rect"; //静态成员属于类, 不会被对象继承; 须冠类名调用 this.width = 阅读全文
posted @ 2009-03-04 11:45 万一 阅读(1685) 评论(0) 推荐(0)