> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/chapter1/12javascript-quan-gong-lve-ff1a-ke-fu-js-de-qi-guai-bu-fen/125han-shu-jian-gou-zi-3001-300c-new-300d-yu-javascript-de-li-shi/1257objectcreate-yu-chun-cui-de-yuan-xing-ji-cheng.md).

# 1.2.5.7.Object.create 與純粹的原型繼承

* 物件建立的方式
  * 1.[new Object](https://jenhsuan.gitbooks.io/javascript-node-js/content/chapter1/1231wu-jian-yu-300c-dian-300d.html)
  * 2.[object literals](https://jenhsuan.gitbooks.io/javascript-node-js/content/chapter1/1232wu-jian-yu-wu-jian-shi-ti.html)
  * 3.[new運算子](https://jenhsuan.gitbooks.io/javascript-node-js/content/chapter1/125han-shu-jian-gou-zi-3001-300c-new-300d-yu-javascript-de-li-shi/1251han-shu-jian-gou-zi-3001-300c-new-300d-yu-javascript-de-li-shi.html)
  * 4.Object.create
* Object.create
  * 舊的瀏覽器可能不支援
  * 是單純的原型繼承
  * 會用原型建立空物件, 其原型就是傳入Object.create的東西
  * 可以覆寫: 如果想要隱藏預設值, 只要新增相同名稱的屬性跟方法到新物件, 而不會改變原型的屬性

```
var person = {
    firstname: 'Default',
    lastname: 'Default',
    greet: function(){
        return 'Hi' + this.firstname;
    }
}

var john = Object.create(person);
console.log(john);
//印出"Hi Default"
console.log(john.greet);

//可以覆寫
john.fistname = 'John'
john.lastname = 'Doe'
```

* polyfill
  * 將engine缺少的功能加進去

```
//polyfill
if (!Object.create) {
    Object.create = function(o) {
        if (argument.length > 1) {
         throw new Error('Object.create implementation' + ' onlyaccepts the first parameter.')
        }
        function F() {}
        F.prototype = o;
        return new F();
    }
}
```
