- javascript中模仿类
function Circle ()
{
}
- 属性和方法
function Circle (xPoint, yPoint, radius)
{
this.x = xPoint; // The x component of the center of the circle.
this.y = yPoint; // The y component of the center of the circle.
this.r = radius; // The radius of the circle.
this.getArea()=function()
{Math.PI*this.r*this.r;}; //return area of the circle.
- 实例化
var circle = new Circle( 1 , 2 , 5 ); // instantiate a Circle object.
var circleArea = circle.getArea(); // get the area of the circle;