设置对象的原型
Object.create(proto[,propertiesObject])
- proto 一个对象,作为新创建对象的原型
- propertiesObject对象的属性定义
实例
var landRover={
name:'landRover',
start:function(){
console.log('%s strat',this.logo);
},
run:function(){
console.log('%s running',this.logo);
},
stop:function(){
console.log('%s stop',this.logo);
}
}
var landWind=Object.create(landRover);
landWind.logo='landWind';
"landWind"
var landCruiser = Object.create(landRover);
landCruiser.logo='landCruiser';
"landCruiser"
landWind.start();
landWind strat
landCruiser.run();
landCruiser running
说明:landWind与landCruiser拥有共同的原型landRover