<script language = "javascript" type = "text/javascript">
          function ImmutableRectangle(w,h) {
              this.getWidth = function() { return w; }
              this.getHeight = function() { return h; }
          }
          ImmutableRectangle.prototype.area = function() {
              return this.getWidth() * this.getHeight();
          }
          ImmutableRectangle tt = new ImmutableRectangle(4,7)
          document.write(tt.area());
         // ImmutableRectangle hhh = new ImmutableRectangle(4,5);
      </script>ImmutableRectangle tt = new ImmutableRectangle(4,7)此句有错误!怎么修改啊

解决方案 »

  1.   

    var tt = new ImmutableRectangle(4,7);js中没有显示变量类型的.
      

  2.   

     function ImmutableRectangle(w,h) {
                  this.getWidth = function() { return w; }
                  this.getHeight = function() { return h; }
              }
    改成 
    IImmutableRectangle function(w,h)
    {
       this.getWidth = function() { return w; }
       this.getHeight = function() { return h; }
    };
      

  3.   

    这个错误我也经常犯,常见的就是int i = .....;经常找不出来.因为这个写法
    太熟悉了
      

  4.   

    var tt = new ImmutableRectangle(4,7);