使用原型:
function Box(color) // Constructor{ this.color = color;}Box.prototype.getColor = function(){ return this.color;};隐藏“颜色”(有点像私有成员变量):
function Box(col){ var color = col; this.getColor = function() { return color; };}用法:
var blueBox = new Box("blue");alert(blueBox.getColor()); // will alert bluevar greenBox = new Box("green");alert(greenBox.getColor()); // will alert green


