javascript一种新的对象创建方式-Object.create()

function Car (desc) {
    this.desc = desc;
    this.color = "red";
}
 
Car.prototype = {
    getInfo: function() {
      return 'A ' + this.color + ' ' + this.desc + '.';
    }
};
//instantiate object using the constructor function
var car =  Object.create(Car.prototype);
car.color = "blue";
alert(car.getInfo());
复制代码
结果为:A blue undefined.
 
 
这种对象创建方式 在IE8无效,在Chrome有效,我已经测试。
posted @ 2014-04-16 12:23  stma  阅读(99)  评论(0)    收藏  举报