实现ECMAScript 5中的Object.create()函数和Object.getPrototypeOf() 函数

 
function clone(proto) {
    function Dummy() { }
 
    Dummy.prototype             = proto;
    Dummy.prototype.constructor = Dummy;
 
    return new Dummy(); //等价于Object.create(Person);
}
 
var me = clone(Person);

function proto(object) {
    return !object?                null
         : '__proto__' in object?  object.__proto__
         : /* not exposed? */      object.constructor.prototype
}

  更多可以参考这个教程

posted @ 2013-04-26 13:14  令狐葱★  阅读(329)  评论(0编辑  收藏  举报