<HEAD>
<TITLE>ProtoType Object</TITLE>
<SCRIPT LANGUAGE="JavaScript">
  function Circle(x,y,r)
  {
    this.x=x;
this.y=y;
this.r=r;
  }
  
  function circleArea()
  {
    return this.pi*this.r*this.r;
  }  function girth()
  {
    return this.pi*this.r*2;
  }  Circle.prototype.pi=3.1415926;
  Circle.prototype.area=circleArea;
  Circle.prototype.girth=girth  var c=new Circle(20,30,40);
  var a=c.area();   //  error: 缺少函数 
  var g=c.girth();  //  error: 缺少函数  alert(c);
  alert(a);
  alert(g);</SCRIPT>
</HEAD>

解决方案 »

  1.   

    <HEAD>
    <TITLE>ProtoType Object</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
      function Circle(x,y,r)
      {
        this.x=x;
    this.y=y;
    this.r=r;
      }
      
      function circleArea()
      {
        return this.pi*this.r*this.r;
      }  function girth()
      {
        return this.pi*this.r*2;
      }  Circle.prototype.pi=3.1415926;
      Circle.prototype.area=circleArea;
      Circle.prototype.girth=girth  var c=new Circle(20,30,40);
      var a=c.area();   //  error: 缺少函数 
      var g=c.girth();  //  error: 缺少函数  alert(c);
      alert(a);
      alert(g);</SCRIPT>
    </HEAD>
      

  2.   

    <HEAD>
    <TITLE>ProtoType Object</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
      function Circle(x,y,r)
      {
        this.x=x;
    this.y=y;
    this.r=r;
      }
      
      function circleArea()
      {
        return this.pi*this.r*this.r;
      }  function girth()
      {
        return this.pi*this.r*2;
      }  Circle.prototype.pi=3.1415926;
      Circle.prototype.area=circleArea;
      Circle.prototype.girth=girth  var c=new Circle(20,30,40);
      var a=c.area();   //  error: 缺少函数 
      var g=c.girth();  //  error: 缺少函数  alert(c);
      alert(a);
      alert(g);</SCRIPT>
    </HEAD>