English 中文(简体)
Java字: 未定义的目的
原标题:Error in Javascript: Object not defined
  • 时间:2012-05-20 17:15:11
  •  标签:
  • javascript

我在Html档案中附上了javascript。 这给我留下了错误,即“肠道圈子是无法界定的,有助于我解决这个问题。

<html>
    <body>
    <h1> Testing Object-based Javascipt </h1>
    <script type="text/javascript">
    function mycircle(x,y,r)
    {
    this.xcoord=x;
    this.ycoord=y;
    this.radius=r;
    this.area = getArea;
    this.getCircumference = function () { return (2 * Math.PI * this.radius ) ; };
    }
   function getArea()
   {
   return (Math.PI * this.radius * this.radius);
   }
        var testCircle = mycircle(3,4,5);

   window.alert( The radius of my circle is   + testCircle.radius);

   </script>

   </body>
   </html>

Thanks in advance....

最佳回答
var testCircle = mycircle(3, 4, 5);

应当:

var testCircle = new mycircle(3, 4, 5);

内容提要请上<代码>新关键词。 如不使用关键词,请重新指定<密码>的回报价值。 并作为<条码>。 页: 1

问题回答

The error I m getting is radius of undefined. If this is the case. You need to return this at the end of mycircle if you planned to use it without new constructor.

updated: The fiddle here

Fix: Broken link





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签