寄生式继承

2019-07-14  本文已影响0人  南蓝NL
function createDog(obj){
 var clone = Object(obj);
 clone.getColor = function(){
   console.log(clone.color)
 }
 return clone
}

var dog = {
 species: '贵宾犬',
 color: 'yellow'
}

var dog1 = createDog(dog);
dog1.getColor();  // yellow
上一篇 下一篇

猜你喜欢

热点阅读