摘要:
定义Circle类,拥有成员变量r,常量PI和计算面积的成员函数area()Javascript代码//第1种写法function Circle(r) {this.r = r;}Circle.PI = 3.14159;Circle.prototype.area = function() {return Circle.PI * this.r * this.r;}var c = new Circle(1.0);alert(c.area());Javascript代码//第2种写法var Circle = function() {var obj = new Object();obj.PI = 3.1 阅读全文