docs: no class inheritance (#47433)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Erick Zhao <ezhao@slack-corp.com>
This commit is contained in:
trop[bot] 2025-06-10 13:12:24 +02:00 committed by GitHub
commit e90404be7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 67 additions and 6 deletions

View file

@ -99,6 +99,10 @@ Process: [Main](../glossary.md#main-process)
It creates a new `BaseWindow` with native properties as set by the `options`. It creates a new `BaseWindow` with native properties as set by the `options`.
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### `new BaseWindow([options])` ### `new BaseWindow([options])`
* `options` [BaseWindowConstructorOptions](structures/base-window-options.md?inline) (optional) * `options` [BaseWindowConstructorOptions](structures/base-window-options.md?inline) (optional)

View file

@ -38,6 +38,10 @@ Process: [Main](../glossary.md#main-process)
This module cannot be used until the `ready` event of the `app` This module cannot be used until the `ready` event of the `app`
module is emitted. module is emitted.
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### Example ### Example
```js ```js

View file

@ -150,6 +150,10 @@ Process: [Main](../glossary.md#main-process)
It creates a new `BrowserWindow` with native properties as set by the `options`. It creates a new `BrowserWindow` with native properties as set by the `options`.
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### `new BrowserWindow([options])` ### `new BrowserWindow([options])`
* `options` [BrowserWindowConstructorOptions](structures/browser-window-options.md?inline) (optional) * `options` [BrowserWindowConstructorOptions](structures/browser-window-options.md?inline) (optional)

View file

@ -42,6 +42,10 @@ Process: [Main](../glossary.md#main-process)
`ImageView` is an [EventEmitter][event-emitter]. `ImageView` is an [EventEmitter][event-emitter].
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### `new ImageView()` _Experimental_ ### `new ImageView()` _Experimental_
Creates an ImageView. Creates an ImageView.

View file

@ -11,6 +11,10 @@ Process: [Main](../glossary.md#main-process)
<!-- TODO(samuelmaddock): refactor doc gen to allow generics to reduce duplication --> <!-- TODO(samuelmaddock): refactor doc gen to allow generics to reduce duplication -->
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### Instance Methods ### Instance Methods
#### `ipcMainServiceWorker.on(channel, listener)` #### `ipcMainServiceWorker.on(channel, listener)`

View file

@ -6,6 +6,10 @@ Process: [Main](../glossary.md#main-process)
See [`Menu`](menu.md) for examples. See [`Menu`](menu.md) for examples.
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### `new MenuItem(options)` ### `new MenuItem(options)`
* `options` Object * `options` Object

View file

@ -6,6 +6,10 @@
Process: [Main](../glossary.md#main-process) Process: [Main](../glossary.md#main-process)
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### `new Menu()` ### `new Menu()`
Creates a new menu. Creates a new menu.

View file

@ -33,6 +33,10 @@ ipcRenderer.on('port', (e) => {
}) })
``` ```
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### Instance Properties ### Instance Properties
#### `channel.port1` #### `channel.port1`

View file

@ -4,12 +4,9 @@
Process: [Main](../glossary.md#main-process) Process: [Main](../glossary.md#main-process)
:::info Renderer process notifications > [!NOTE]
> If you want to show notifications from a renderer process you should use the
If you want to show notifications from a renderer process you should use the > [web Notifications API](../tutorial/notifications.md)
[web Notifications API](../tutorial/notifications.md)
:::
## Class: Notification ## Class: Notification
@ -21,6 +18,10 @@ Process: [Main](../glossary.md#main-process)
It creates a new `Notification` with native properties as set by the `options`. It creates a new `Notification` with native properties as set by the `options`.
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### Static Methods ### Static Methods
The `Notification` class has the following static methods: The `Notification` class has the following static methods:

View file

@ -13,6 +13,10 @@ For including the share menu as a submenu of other menus, please use the
Process: [Main](../glossary.md#main-process) Process: [Main](../glossary.md#main-process)
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### `new ShareMenu(sharingItem)` ### `new ShareMenu(sharingItem)`
* `sharingItem` SharingItem - The item to share. * `sharingItem` SharingItem - The item to share.

View file

@ -1,5 +1,9 @@
# TouchBar # TouchBar
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
## Class: TouchBar ## Class: TouchBar
> Create TouchBar layouts for native macOS applications > Create TouchBar layouts for native macOS applications

View file

@ -25,6 +25,10 @@ app.whenReady().then(() => {
}) })
``` ```
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
**Platform Considerations** **Platform Considerations**
**Linux** **Linux**

View file

@ -25,6 +25,10 @@ Process: [Main](../glossary.md#main-process)
`View` is an [EventEmitter][event-emitter]. `View` is an [EventEmitter][event-emitter].
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### `new View()` ### `new View()`
Creates a new `View`. Creates a new `View`.

View file

@ -32,6 +32,10 @@ Process: [Main](../glossary.md#main-process)
`WebContentsView` is an [EventEmitter][event-emitter]. `WebContentsView` is an [EventEmitter][event-emitter].
> [!WARNING]
> Electron's built-in classes cannot be subclassed in user code.
> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules).
### `new WebContentsView([options])` ### `new WebContentsView([options])`
* `options` Object (optional) * `options` Object (optional)

View file

@ -152,6 +152,14 @@ The effect is visible only on (some?) LCD screens. Even if you don't see a diffe
Notice that just setting the background in the CSS does not have the desired effect. Notice that just setting the background in the CSS does not have the desired effect.
## Class inheritance does not work with Electron built-in modules
Electron classes cannot be subclassed with the [`extends`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends)
keyword (also known as class inheritance). This feature was never implemented in Electron due
to the added complexity it would add to C++/JavaScript interop in Electron's internals.
For more information, see [electron/electron#23](https://github.com/electron/electron/issues/23).
[memory-management]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management [memory-management]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management
[closures]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures [closures]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
[storage]: https://developer.mozilla.org/en-US/docs/Web/API/Storage [storage]: https://developer.mozilla.org/en-US/docs/Web/API/Storage