JS笔记:构造函数,类,类属性,类方法
- <script type="text/javascript">
- function Circle(radius){
- this.r = radius;
- }
- Circle.PI = 3.1415926;
- Circle.prototype.area = function(){
- return Circle.PI * this.r * this.r;
- }
- Circle.max = function(a,b){
- if(a.r > b.r) return a;
- else return b;
- }
- var c = new Circle(1.0);
- c.r = 2.2;
- var d = new Circle(1.2);
- alert(Circle.max(c,d).r);
- </script>
陈老师写教材,每写一篇,就得吓死一片人。
25 九月 2008, 7:45 上午