知識社群登入
Constructor, prototype
by 蘇德宙, 2011-02-05 20:28, 人氣(1465)
// object constructor function
function obj(name, size) {
  this.name = name;
  this.size = size;
}
 
obj.prototype.tellSize = function() { return this.size; }
var o1 = new obj();            // no color
obj.prototype.color = "blue";
var o2 = new obj();            // has color