原型模式不是很常用,了解一下就可以
Object.create()使用现有的对象来创建对象的__proto__
最下面代码的实例 x = 下面代码
x = {
first: 'x',
last: 'y',
__proto : {
getName:function(){},
say: function(){}
}
}
const prototype = {
getName: function() {
return this.first + '---' + this.last
},
say: function() {
alert('hello')
}
}
let x = Object.create(prototype)
console.log(x);
x.first = 'x'
x.last = 'y'
alert(x.getName())
x.say()