$(function(){
var Person={
name:"LALA",
sayName:function(){
console.log(this.name);
}
}
var p = Object.create()(Person);
console.log(p);//对象Person的属性成为了p的原型属性,也就是说 p 原型继承自 Person
p.sayName()
//那Object.create()这个方法怎么实现这个功能呢?
@* Object.create = function(prototype){
function Func(){};
Func.prototype = prototype;//将该prototype作为Func这个构造函数的原型对象
var o = new Func();
return o;
} *@
});
显而易见,这用使用Object.create()方法封装对象的途径也是非常简洁方便的。