JavaScript中的类都具有一个原型(prototype)对象, 可以为类的原型对象定义属性,类的实例能够从原型对象处“继承”这些属性。
function Circle(x,y,r)

...{
this.x = x;
this.y = y;
this.r = r;
}
var wheel = new Circle(0,0,5);
document.write("wheel=new Circle(0,0,5);<br/>");
//为Circle的prototype设置属性pi
Circle.prototype.pi = 3.14;

function Circle_circumference()

...{
return 2*this.pi*this.r;
}
//为Circle的prototype设置方法Circle_circumference()
Circle.prototype.circumference = Circle_circumference;
//wheel自动继承其prototype的属性与方法
var C1 = wheel.circumference();
document.write("C1=" + C1 + "<br/>");
//为wheel设置pi属性后,覆盖了其prototype的属性pi
wheel.pi = 3.14159;
var C2 = wheel.circumference();
document.write("C2=" + C2 + "<br/>");
//删除wheel对象的pi属性,prototype的pi生效
delete wheel.pi;
var C3 = wheel.circumference();
document.write("C3=" + C3 + "<br/>");





























