# class A vs. class A extends Object

{% tabs %}
{% tab title="💾 程式" %}
{% hint style="info" %} <mark style="color:blue;">**class A extends Object**</mark> 與 <mark style="color:blue;">**class A**</mark> 最大的不同就是：

* 改變繼承路線，繼承了 [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) (而不是 Function.prototype)
* 變成 <mark style="color:orange;">**derived class**</mark> (而不是 base class)，因此在 <mark style="color:purple;">**constructor**</mark> (如果有的話) 內必須呼叫 [super](/web/js/val/class/inheritance/super.md)。
  {% endhint %}

![](/files/gQeUeefSPm2nm1X0a0zz)

* replit ⟩ [class A vs class A extends Object](https://replit.com/@pegasusroe/JS-class-A-vs-class-A-extends-Object#index.js)

```javascript
// -------------------------------------------
// ⭐ B can access Object's "static methods",
// ⭐ but A can't❗
// -------------------------------------------
class A {}
class B extends Object {}

const obj = { name: 'Joe', age: 21 };

// ⛔ TypeError: `A.getOwnPropertyNames` is not a function❗
A.getOwnPropertyNames(obj);

// ⭐ normally call `Object.getOwnPropertyNames(obj)` directly.
B.getOwnPropertyNames(obj),    // [ 'name', 'age' ]
```

{% endtab %}

{% tab title="📗 參考" %}

* [x] JS.info ⟩ [Class extends Object?](https://javascript.info/static-properties-methods#class-extends-object)&#x20;
  {% endtab %}

{% tab title="📘 手冊" %}

* MDN ⟩ [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) ⟩&#x20;
  * [JavaScript Guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide) ⟩ [Working with objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects)
  * [built-in objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects) ⟩&#x20;
    * [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
    * [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
      {% endtab %}
      {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/val/obj/extend/inheritance/class-a-vs.-class-a-extends-object.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
