JS笔记:构造函数,类,类属性,类方法

  1. <script type="text/javascript">
  2.         function Circle(radius){
  3.             this.r = radius;
  4.         }
  5.         Circle.PI = 3.1415926;
  6.         Circle.prototype.area = function(){
  7.             return Circle.PI * this.r * this.r;
  8.         }
  9.         Circle.max = function(a,b){
  10.             if(a.r > b.r) return a;
  11.             else return b;
  12.         }
  13.        
  14.         var c = new Circle(1.0);
  15.         c.r = 2.2;
  16.         var d = new Circle(1.2);
  17.         alert(Circle.max(c,d).r);
  18.     </script>

相关文章

One Comment

  1. Paro:

    陈老师写教材,每写一篇,就得吓死一片人。

留下评论