Полезная информация

Список ответов на каверзные вопросы можно получить в FAQ-разделе форума.

Разработка » в помеченной строке выдается ошибка p1 undefined Почему? » 07-03-2009 13:18:26

[code]<html>
<head>
  </head>
<body>
  <canvas height="600" width="800" id="canvas" />

<script type="text/javascript">
function Point(x,y)
{
     this.x = x;
     this.y = y;
}

function Line(p1,p2)
{
     this.p1 = p1;
     this.p2 = p2;
     this.length = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));  /////////error here********************
}


function Shape()
{
     this.points = [];   /////////////
     this.lines = [];    //////////////
     this.init();
}


Shape.prototype = {
     constructor:Shape,
     init: function()
     {
         if(typeof this.context === 'undefined')
         {
             var canvas = document.getElementById('canvas');
             Shape.prototype.context = canvas.getContext('2d');
         }
     },
    draw: function()
     {
        var ctx = this.context;
        ctx.strokeStyle = this.getColor();
        ctx.beginPath();
        ctx.moveTo(this.points[0].x, this.points[0].y);
        for(var i=1; i<this.points.length; i++)
            ctx.lineTo(this.points[i].x, this.points[i].y);
       
        ctx.closePath();
        ctx.stroke();
     },
    get

Board footer

Powered by PunBB
Modified by Mozilla Russia
Copyright © 2004–2020 Mozilla Russia GitHub mark
Язык отображения форума: [Русский] [English]