对象关联和行为委托 对象关联和行为委托创建关联1234567let foo = { something: function(){ console.log("Tell me something good...") }};let bar = Object.create(foo); //Object.create(..)会创建一个新对象(bar)并把它关联到我们指定的对象(foo)bar.something() //当something不存在bar,会把ta委托给foo 利用prototype进行委托1234567891011121314151617181920212223//利用[[Prototype]]把b1委托给Bar并把Bar委托给Foo,实现了三个对象之间的关联。Foo = { init:function(who){ this.me = who; }, identify:function(){ return "I am " + this.me } } Bar = Object.create(Foo); Bar.speak = function(){ alert("Hello,"+ this.identify()+".") }; var b1 = Object.create(Bar); b1.init("b1") var b2 = Object.create(Bar); b2.init("b2") b1.speak(); b2.speak();